GraphQL\Executor\Executor::collectFields PHP Method

collectFields() private static method

CollectFields requires the "runtime type" of an object. For a field which returns and Interface or Union type, the "runtime type" will be the actual Object type returned by that field.
private static collectFields ( ExecutionContext $exeContext, ObjectType $runtimeType, SelectionSetNode $selectionSet, $fields, $visitedFragmentNames ) : ArrayObject
$exeContext ExecutionContext
$runtimeType GraphQL\Type\Definition\ObjectType
$selectionSet GraphQL\Language\AST\SelectionSetNode
$fields
$visitedFragmentNames
return ArrayObject
    private static function collectFields(ExecutionContext $exeContext, ObjectType $runtimeType, SelectionSetNode $selectionSet, $fields, $visitedFragmentNames)
    {
        foreach ($selectionSet->selections as $selection) {
            switch ($selection->kind) {
                case NodeKind::FIELD:
                    if (!self::shouldIncludeNode($exeContext, $selection->directives)) {
                        continue;
                    }
                    $name = self::getFieldEntryKey($selection);
                    if (!isset($fields[$name])) {
                        $fields[$name] = new \ArrayObject();
                    }
                    $fields[$name][] = $selection;
                    break;
                case NodeKind::INLINE_FRAGMENT:
                    if (!self::shouldIncludeNode($exeContext, $selection->directives) || !self::doesFragmentConditionMatch($exeContext, $selection, $runtimeType)) {
                        continue;
                    }
                    self::collectFields($exeContext, $runtimeType, $selection->selectionSet, $fields, $visitedFragmentNames);
                    break;
                case NodeKind::FRAGMENT_SPREAD:
                    $fragName = $selection->name->value;
                    if (!empty($visitedFragmentNames[$fragName]) || !self::shouldIncludeNode($exeContext, $selection->directives)) {
                        continue;
                    }
                    $visitedFragmentNames[$fragName] = true;
                    /** @var FragmentDefinitionNode|null $fragment */
                    $fragment = isset($exeContext->fragments[$fragName]) ? $exeContext->fragments[$fragName] : null;
                    if (!$fragment || !self::doesFragmentConditionMatch($exeContext, $fragment, $runtimeType)) {
                        continue;
                    }
                    self::collectFields($exeContext, $runtimeType, $fragment->selectionSet, $fields, $visitedFragmentNames);
                    break;
            }
        }
        return $fields;
    }