Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

PossibleFragmentSpreads::getVisitorpublicWC 1.0

Method of the class: PossibleFragmentSpreads{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

PossibleFragmentSpreads::getVisitor() code WC 10.9.1

public function getVisitor(QueryValidationContext $context): array
{
    return [
        NodeKind::INLINE_FRAGMENT => function (InlineFragmentNode $node) use ($context): void {
            $fragType = $context->getType();
            $parentType = $context->getParentType();

            if (
                ! $fragType instanceof CompositeType
                || ! $parentType instanceof CompositeType
                || $this->doTypesOverlap($context->getSchema(), $fragType, $parentType)
            ) {
                return;
            }

            $context->reportError(new Error(
                static::typeIncompatibleAnonSpreadMessage($parentType->toString(), $fragType->toString()),
                [$node]
            ));
        },
        NodeKind::FRAGMENT_SPREAD => function (FragmentSpreadNode $node) use ($context): void {
            $fragName = $node->name->value;
            $fragType = $this->getFragmentType($context, $fragName);
            $parentType = $context->getParentType();

            if (
                $fragType === null
                || $parentType === null
                || $this->doTypesOverlap($context->getSchema(), $fragType, $parentType)
            ) {
                return;
            }

            $context->reportError(new Error(
                static::typeIncompatibleSpreadMessage($fragName, $parentType->toString(), $fragType->toString()),
                [$node]
            ));
        },
    ];
}