public function __invoke(ValidationContext $context)
{
return [Node::INLINE_FRAGMENT => function (InlineFragment $node) use($context) {
$fragType = Type::getNamedType($context->getType());
$parentType = $context->getParentType();
if ($fragType && $parentType && !$this->doTypesOverlap($fragType, $parentType)) {
return new Error(self::typeIncompatibleAnonSpreadMessage($parentType, $fragType), [$node]);
}
}, Node::FRAGMENT_SPREAD => function (FragmentSpread $node) use($context) {
$fragName = $node->name->value;
$fragType = Type::getNamedType($this->getFragmentType($context, $fragName));
$parentType = $context->getParentType();
if ($fragType && $parentType && !$this->doTypesOverlap($fragType, $parentType)) {
return new Error(self::typeIncompatibleSpreadMessage($fragName, $parentType, $fragType), [$node]);
}
}];
}