Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

FragmentsOnCompositeTypes::getVisitorpublicWC 1.0

Method of the class: FragmentsOnCompositeTypes{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

FragmentsOnCompositeTypes::getVisitor() code WC 10.9.1

public function getVisitor(QueryValidationContext $context): array
{
    return [
        NodeKind::INLINE_FRAGMENT => static function (InlineFragmentNode $node) use ($context): void {
            if ($node->typeCondition === null) {
                return;
            }

            $type = AST::typeFromAST([$context->getSchema(), 'getType'], $node->typeCondition);
            if ($type === null || Type::isCompositeType($type)) {
                return;
            }

            $context->reportError(new Error(
                static::inlineFragmentOnNonCompositeErrorMessage($type->toString()),
                [$node->typeCondition]
            ));
        },
        NodeKind::FRAGMENT_DEFINITION => static function (FragmentDefinitionNode $node) use ($context): void {
            $type = AST::typeFromAST([$context->getSchema(), 'getType'], $node->typeCondition);

            if ($type === null || Type::isCompositeType($type)) {
                return;
            }

            $context->reportError(new Error(
                static::fragmentOnNonCompositeErrorMessage(
                    $node->name->value,
                    Printer::doPrint($node->typeCondition)
                ),
                [$node->typeCondition]
            ));
        },
    ];
}