public function testOutputTypesAreInvalid() { $this->expectFailsRule(new VariablesAreInputTypes(), ' query Foo($a: Dog, $b: [[DogOrCat!]]!, $c: Pet) { field(a: $a, b: $b, c: $c) } ', [new FormattedError(Messages::nonInputTypeOnVarMessage('a', 'Dog'), [new SourceLocation(2, 21)]), new FormattedError(Messages::nonInputTypeOnVarMessage('b', '[[DogOrCat!]]!'), [new SourceLocation(2, 30)]), new FormattedError(Messages::nonInputTypeOnVarMessage('c', 'Pet'), [new SourceLocation(2, 50)])]); }
public function __invoke(ValidationContext $context) { return [Node::VARIABLE_DEFINITION => function (VariableDefinition $node) use($context) { $typeName = $this->getTypeASTName($node->type); $type = $context->getSchema()->getType($typeName); if (!$type instanceof InputType) { $variableName = $node->variable->name->value; return new Error(Messages::nonInputTypeOnVarMessage($variableName, Printer::doPrint($node->type)), [$node->type]); } }]; }