Fix how TypeInfo handles inline fragments without type

ref: graphql/graphql-js#1041
This commit is contained in:
Daniel Tschinder 2018-02-08 15:13:31 +01:00
parent 94525c0025
commit eb9ac66af8
2 changed files with 6 additions and 2 deletions

View File

@ -331,7 +331,7 @@ class TypeInfo
case NodeKind::INLINE_FRAGMENT: case NodeKind::INLINE_FRAGMENT:
case NodeKind::FRAGMENT_DEFINITION: case NodeKind::FRAGMENT_DEFINITION:
$typeConditionNode = $node->typeCondition; $typeConditionNode = $node->typeCondition;
$outputType = $typeConditionNode ? self::typeFromAST($schema, $typeConditionNode) : $this->getType(); $outputType = $typeConditionNode ? self::typeFromAST($schema, $typeConditionNode) : Type::getNamedType($this->getType());
$this->typeStack[] = Type::isOutputType($outputType) ? $outputType : null; // push $this->typeStack[] = Type::isOutputType($outputType) ? $outputType : null; // push
break; break;

View File

@ -1127,7 +1127,7 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
$typeInfo = new TypeInfo(TestCase::getDefaultSchema()); $typeInfo = new TypeInfo(TestCase::getDefaultSchema());
$ast = Parser::parse('{ human(id: 4) { name, pets { name }, unknown } }'); $ast = Parser::parse('{ human(id: 4) { name, pets { ... { name } }, unknown } }');
Visitor::visit($ast, Visitor::visitWithTypeInfo($typeInfo, [ Visitor::visit($ast, Visitor::visitWithTypeInfo($typeInfo, [
'enter' => function ($node) use ($typeInfo, &$visited) { 'enter' => function ($node) use ($typeInfo, &$visited) {
$parentType = $typeInfo->getParentType(); $parentType = $typeInfo->getParentType();
@ -1179,10 +1179,14 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
['enter', 'Name', 'pets', 'Human', '[Pet]', null], ['enter', 'Name', 'pets', 'Human', '[Pet]', null],
['leave', 'Name', 'pets', 'Human', '[Pet]', null], ['leave', 'Name', 'pets', 'Human', '[Pet]', null],
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null], ['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
['enter', 'InlineFragment', null, 'Pet', 'Pet', null],
['enter', 'SelectionSet', null, 'Pet', 'Pet', null],
['enter', 'Field', null, 'Pet', 'String', null], ['enter', 'Field', null, 'Pet', 'String', null],
['enter', 'Name', 'name', 'Pet', 'String', null], ['enter', 'Name', 'name', 'Pet', 'String', null],
['leave', 'Name', 'name', 'Pet', 'String', null], ['leave', 'Name', 'name', 'Pet', 'String', null],
['leave', 'Field', null, 'Pet', 'String', null], ['leave', 'Field', null, 'Pet', 'String', null],
['leave', 'SelectionSet', null, 'Pet', 'Pet', null],
['leave', 'InlineFragment', null, 'Pet', 'Pet', null],
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null], ['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
['leave', 'Field', null, 'Human', '[Pet]', null], ['leave', 'Field', null, 'Human', '[Pet]', null],
['enter', 'Field', null, 'Human', null, null], ['enter', 'Field', null, 'Human', null, null],