Automattic\WooCommerce\Vendor\GraphQL\Executor
ReferenceExecutor::collectFields
Given a selectionSet, adds all fields in that selection to the passed in map of fields, and returns it at the end.
CollectFields requires the "runtime type" of an object. For a field which returns an Interface or Union type, the "runtime type" will be the actual Object type returned by that field.
Method of the class: ReferenceExecutor{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->collectFields( $runtimeType, $selectionSet, $fields, $visitedFragmentNames ): \ArrayObject;
- $runtimeType(ObjectType) (required)
- .
- $selectionSet(SelectionSetNode) (required)
- .
- $fields(ArrayObject) (required)
- .
- $visitedFragmentNames(ArrayObject) (required)
- .
ReferenceExecutor::collectFields() ReferenceExecutor::collectFields code WC 10.9.1
protected function collectFields(
ObjectType $runtimeType,
SelectionSetNode $selectionSet,
\ArrayObject $fields,
\ArrayObject $visitedFragmentNames
): \ArrayObject {
$exeContext = $this->exeContext;
foreach ($selectionSet->selections as $selection) {
switch (true) {
case $selection instanceof FieldNode:
if (! $this->shouldIncludeNode($selection)) {
break;
}
$name = static::getFieldEntryKey($selection);
$fields[$name] ??= new \ArrayObject();
$fields[$name][] = $selection;
break;
case $selection instanceof InlineFragmentNode:
if (
! $this->shouldIncludeNode($selection)
|| ! $this->doesFragmentConditionMatch($selection, $runtimeType)
) {
break;
}
$this->collectFields(
$runtimeType,
$selection->selectionSet,
$fields,
$visitedFragmentNames
);
break;
case $selection instanceof FragmentSpreadNode:
$fragName = $selection->name->value;
if (isset($visitedFragmentNames[$fragName]) || ! $this->shouldIncludeNode($selection)) {
break;
}
$visitedFragmentNames[$fragName] = true;
if (! isset($exeContext->fragments[$fragName])) {
break;
}
$fragment = $exeContext->fragments[$fragName];
if (! $this->doesFragmentConditionMatch($fragment, $runtimeType)) {
break;
}
$this->collectFields(
$runtimeType,
$fragment->selectionSet,
$fields,
$visitedFragmentNames
);
break;
}
}
return $fields;
}