GraphQL\Executor\Executor::executeFields PHP Method

executeFields() private static method

Implements the "Evaluating selection sets" section of the spec for "read" mode.
private static executeFields ( ExecutionContext $exeContext, ObjectType $parentType, $source, $path, $fields ) : GraphQL\Executor\Promise\Promise | stdClass | array
$exeContext ExecutionContext
$parentType GraphQL\Type\Definition\ObjectType
$source
$path
$fields
return GraphQL\Executor\Promise\Promise | stdClass | array
    private static function executeFields(ExecutionContext $exeContext, ObjectType $parentType, $source, $path, $fields)
    {
        $containsPromise = false;
        $finalResults = [];
        foreach ($fields as $responseName => $fieldNodes) {
            $fieldPath = $path;
            $fieldPath[] = $responseName;
            $result = self::resolveField($exeContext, $parentType, $source, $fieldNodes, $fieldPath);
            if ($result === self::$UNDEFINED) {
                continue;
            }
            if (!$containsPromise && self::$promiseAdapter->isPromise($result)) {
                $containsPromise = true;
            }
            $finalResults[$responseName] = $result;
        }
        // If there are no promises, we can just return the object
        if (!$containsPromise) {
            return self::fixResultsIfEmptyArray($finalResults);
        }
        // Otherwise, results is a map from field name to the result
        // of resolving that field, which is possibly a promise. Return
        // a promise that will return this same map, but with any
        // promises replaced with the values they resolved to.
        return self::$promiseAdapter->createPromiseAll($finalResults)->then(function ($resolvedResults) {
            return self::fixResultsIfEmptyArray($resolvedResults);
        });
    }