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]);
}
}
}
}];
}