From 50cbfb4a44615e6f2bad427b5f5e87409ebb8307 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 13 Feb 2018 18:08:05 +0100 Subject: [PATCH] Fix Bug in PossibleFragmentSpreads validator ref: graphql/graphql-js@7e147a8dd60496505cd5d491fb7126b2319095c9 --- src/Validator/Rules/PossibleFragmentSpreads.php | 8 +++++++- tests/Validator/PossibleFragmentSpreadsTest.php | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 */