Automattic\WooCommerce\Vendor\GraphQL\Validator

QueryValidationContext::getRecursivelyReferencedFragmentspublicWC 1.0

Method of the class: QueryValidationContext{}

No Hooks.

Returns

Array. FragmentDefinitionNode>

Usage

$QueryValidationContext = new QueryValidationContext();
$QueryValidationContext->getRecursivelyReferencedFragments( $operation ): array;
$operation(OperationDefinitionNode) (required)
.

QueryValidationContext::getRecursivelyReferencedFragments() code WC 10.9.1

public function getRecursivelyReferencedFragments(OperationDefinitionNode $operation): array
{
    $fragments = $this->recursivelyReferencedFragments[$operation] ?? null;

    if ($fragments === null) {
        $fragments = [];
        $collectedNames = [];
        $nodesToVisit = [$operation];
        while ($nodesToVisit !== []) {
            $node = array_pop($nodesToVisit);
            $spreads = $this->getFragmentSpreads($node);
            foreach ($spreads as $spread) {
                $fragName = $spread->name->value;

                if ($collectedNames[$fragName] ?? false) {
                    continue;
                }

                $collectedNames[$fragName] = true;
                $fragment = $this->getFragment($fragName);
                if ($fragment === null) {
                    continue;
                }

                $fragments[] = $fragment;
                $nodesToVisit[] = $fragment;
            }
        }

        $this->recursivelyReferencedFragments[$operation] = $fragments;
    }

    return $fragments;
}