Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

VariablesAreInputTypes::getVisitorpublicWC 1.0

Method of the class: VariablesAreInputTypes{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

VariablesAreInputTypes::getVisitor() code WC 10.9.1

public function getVisitor(QueryValidationContext $context): array
{
    return [
        NodeKind::VARIABLE_DEFINITION => static function (VariableDefinitionNode $node) use ($context): void {
            $type = AST::typeFromAST([$context->getSchema(), 'getType'], $node->type);

            // If the variable type is not an input type, return an error.
            if ($type === null || Type::isInputType($type)) {
                return;
            }

            $variableName = $node->variable->name->value;
            $context->reportError(new Error(
                static::nonInputTypeOnVarMessage($variableName, Printer::doPrint($node->type)),
                [$node->type]
            ));
        },
    ];
}