Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::completeObjectValueprotectedWC 1.0

Complete an Object value by executing all sub-selections.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

Array|Promise|\stdClass.

Usage

// protected - for code of main (parent) or child class
$result = $this->completeObjectValue( $returnType, $fieldNodes, $info, $path, $unaliasedPath, $result, $contextValue );
$returnType(ObjectType) (required)
.
$fieldNodes(ArrayObject) (required)
.
$info(ResolveInfo) (required)
.
$path(list<string|int>) (required)
.
$unaliasedPath(list<string|int>) (required)
.
$result(mixed) (required)
.
$contextValue(mixed) (required)
.

ReferenceExecutor::completeObjectValue() code WC 10.9.1

protected function completeObjectValue(
    ObjectType $returnType,
    \ArrayObject $fieldNodes,
    ResolveInfo $info,
    array $path,
    array $unaliasedPath,
    $result,
    $contextValue
) {
    // If there is an isTypeOf predicate function, call it with the
    // current result. If isTypeOf returns false, then raise an error rather
    // than continuing execution.
    $isTypeOf = $returnType->isTypeOf($result, $contextValue, $info);
    if ($isTypeOf !== null) {
        $promise = $this->getPromise($isTypeOf);
        if ($promise !== null) {
            return $promise->then(function ($isTypeOfResult) use (
                $contextValue,
                $returnType,
                $fieldNodes,
                $path,
                $unaliasedPath,
                $result
            ) {
                if (! $isTypeOfResult) {
                    throw $this->invalidReturnTypeError($returnType, $result, $fieldNodes);
                }

                return $this->collectAndExecuteSubfields(
                    $returnType,
                    $fieldNodes,
                    $path,
                    $unaliasedPath,
                    $result,
                    $contextValue
                );
            });
        }

        assert(is_bool($isTypeOf), 'Promise would return early');
        if (! $isTypeOf) {
            throw $this->invalidReturnTypeError($returnType, $result, $fieldNodes);
        }
    }

    return $this->collectAndExecuteSubfields(
        $returnType,
        $fieldNodes,
        $path,
        $unaliasedPath,
        $result,
        $contextValue
    );
}