Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

UniqueFragmentNames::getVisitorpublicWC 1.0

Method of the class: UniqueFragmentNames{}

No Hooks.

Returns

null. Nothing (null).

Usage

$UniqueFragmentNames = new UniqueFragmentNames();
$UniqueFragmentNames->getVisitor( $context ): array;
$context(QueryValidationContext) (required)
.

UniqueFragmentNames::getVisitor() code WC 10.9.4

public function getVisitor(QueryValidationContext $context): array
{
    $this->knownFragmentNames = [];

    return [
        NodeKind::OPERATION_DEFINITION => static fn (): VisitorOperation => Visitor::skipNode(),
        NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context): VisitorOperation {
            $fragmentName = $node->name->value;
            if (! isset($this->knownFragmentNames[$fragmentName])) {
                $this->knownFragmentNames[$fragmentName] = $node->name;
            } else {
                $context->reportError(new Error(
                    static::duplicateFragmentNameMessage($fragmentName),
                    [$this->knownFragmentNames[$fragmentName], $node->name]
                ));
            }

            return Visitor::skipNode();
        },
    ];
}