public function __invoke(ValidationContext $context) { return [Node::FIELD => function (Field $node) use($context) { $type = $context->getType(); if ($type) { if (Type::isLeafType($type)) { if ($node->selectionSet) { return new Error(Messages::noSubselectionAllowedMessage($node->name->value, $type), [$node->selectionSet]); } } else { if (!$node->selectionSet) { return new Error(Messages::requiredSubselectionMessage($node->name->value, $type), [$node]); } } } }]; }
private function noScalarSubselection($field, $type, $line, $column) { return new FormattedError(Messages::noSubselectionAllowedMessage($field, $type), [new SourceLocation($line, $column)]); }