Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::collectSubFieldsprotectedWC 1.0

A memoized collection of relevant subfields with regard to the return type. Memoizing ensures the subfields are not repeatedly calculated, which saves overhead when resolving lists of values.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->collectSubFields( $returnType, $fieldNodes ): \ArrayObject;
$returnType(ObjectType) (required)
.
$fieldNodes(ArrayObject) (required)
.

ReferenceExecutor::collectSubFields() code WC 10.9.4

protected function collectSubFields(ObjectType $returnType, \ArrayObject $fieldNodes): \ArrayObject
{
    // @phpstan-ignore-next-line generics of SplObjectStorage are not inferred from empty instantiation
    $returnTypeCache = $this->subFieldCache[$returnType] ??= new \SplObjectStorage();

    if (! isset($returnTypeCache[$fieldNodes])) {
        // Collect sub-fields to execute to complete this value.
        $subFieldNodes = new \ArrayObject();
        $visitedFragmentNames = new \ArrayObject();
        foreach ($fieldNodes as $fieldNode) {
            if (isset($fieldNode->selectionSet)) {
                $subFieldNodes = $this->collectFields(
                    $returnType,
                    $fieldNode->selectionSet,
                    $subFieldNodes,
                    $visitedFragmentNames
                );
            }
        }

        $returnTypeCache[$fieldNodes] = $subFieldNodes;
    }

    return $returnTypeCache[$fieldNodes];
}