Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::executeFieldsSeriallyprotectedWC 1.0

Implements the "Evaluating selection sets" section of the spec for "write" mode.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

Array|Promise|\stdClass.

Usage

// protected - for code of main (parent) or child class
$result = $this->executeFieldsSerially( $parentType, $rootValue, $path, $unaliasedPath, $fields, $contextValue );
$parentType(ObjectType) (required)
.
$rootValue(mixed) (required)
.
$path(list<string|int>) (required)
.
$unaliasedPath(list<string|int>) (required)
.
$fields(ArrayObject) (required)
.
$contextValue(mixed) (required)
.

ReferenceExecutor::executeFieldsSerially() code WC 10.9.1

protected function executeFieldsSerially(ObjectType $parentType, $rootValue, array $path, array $unaliasedPath, \ArrayObject $fields, $contextValue)
{
    $result = $this->promiseReduce(
        array_keys($fields->getArrayCopy()),
        function ($results, $responseName) use ($contextValue, $path, $unaliasedPath, $parentType, $rootValue, $fields) {
            $fieldNodes = $fields[$responseName];
            assert($fieldNodes instanceof \ArrayObject, 'The keys of $fields populate $responseName');

            $result = $this->resolveField(
                $parentType,
                $rootValue,
                $fieldNodes,
                $responseName,
                $path,
                $unaliasedPath,
                $this->maybeScopeContext($contextValue)
            );
            if ($result === static::$UNDEFINED) {
                return $results;
            }

            $promise = $this->getPromise($result);
            if ($promise !== null) {
                return $promise->then(static function ($resolvedResult) use ($responseName, $results): array {
                    $results[$responseName] = $resolvedResult;

                    return $results;
                });
            }

            $results[$responseName] = $result;

            return $results;
        },
        []
    );

    $promise = $this->getPromise($result);
    if ($promise !== null) {
        return $result->then(
            static fn ($resolvedResults) => static::fixResultsIfEmptyArray($resolvedResults)
        );
    }

    return static::fixResultsIfEmptyArray($result);
}