public function __invoke(ValidationContext $context)
{
return [Node::INLINE_FRAGMENT => function (InlineFragment $node) use($context) {
$typeName = $node->typeCondition->value;
$type = $context->getSchema()->getType($typeName);
$isCompositeType = $type instanceof CompositeType;
if (!$isCompositeType) {
return new Error("Fragment cannot condition on non composite type \"{$typeName}\".", [$node->typeCondition]);
}
}, Node::FRAGMENT_DEFINITION => function (FragmentDefinition $node) use($context) {
$typeName = $node->typeCondition->value;
$type = $context->getSchema()->getType($typeName);
$isCompositeType = $type instanceof CompositeType;
if (!$isCompositeType) {
return new Error(Messages::fragmentOnNonCompositeErrorMessage($node->name->value, $typeName), [$node->typeCondition]);
}
}];
}