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;
}