diff --git a/src/Validator/Rules/PossibleFragmentSpreads.php b/src/Validator/Rules/PossibleFragmentSpreads.php index 3e7332e..37a24dc 100644 --- a/src/Validator/Rules/PossibleFragmentSpreads.php +++ b/src/Validator/Rules/PossibleFragmentSpreads.php @@ -61,7 +61,13 @@ class PossibleFragmentSpreads extends AbstractValidationRule private function getFragmentType(ValidationContext $context, $name) { $frag = $context->getFragment($name); - return $frag ? TypeInfo::typeFromAST($context->getSchema(), $frag->typeCondition) : null; + if ($frag) { + $type = TypeInfo::typeFromAST($context->getSchema(), $frag->typeCondition); + if ($type instanceof CompositeType) { + return $type; + } + } + return null; } private function doTypesOverlap(Schema $schema, CompositeType $fragType, CompositeType $parentType) diff --git a/tests/Validator/PossibleFragmentSpreadsTest.php b/tests/Validator/PossibleFragmentSpreadsTest.php index d186157..a3139de 100644 --- a/tests/Validator/PossibleFragmentSpreadsTest.php +++ b/tests/Validator/PossibleFragmentSpreadsTest.php @@ -128,6 +128,17 @@ class PossibleFragmentSpreadsTest extends TestCase '); } + /** + * @it ignores incorrect type (caught by FragmentsOnCompositeTypes) + */ + public function testIgnoresIncorrectTypeCaughtByFragmentsOnCompositeTypes() + { + $this->expectPassesRule(new PossibleFragmentSpreads, ' + fragment petFragment on Pet { ...badInADifferentWay } + fragment badInADifferentWay on String { name } + '); + } + /** * @it different object into object */