public function __invoke(ValidationContext $context)
{
return [NodeKind::FIELD => function (FieldNode $node) use($context) {
$type = $context->getType();
if ($type) {
if (Type::isLeafType($type)) {
if ($node->selectionSet) {
$context->reportError(new Error(self::noSubselectionAllowedMessage($node->name->value, $type), [$node->selectionSet]));
}
} else {
if (!$node->selectionSet) {
$context->reportError(new Error(self::requiredSubselectionMessage($node->name->value, $type), [$node]));
}
}
}
}];
}