ResolveInfo: Take in account inline fragments in getFieldSelection()

This commit is contained in:
Vladimir Razuvaev 2017-03-10 19:21:27 +07:00
parent 827bfa7907
commit f77bd17eba
2 changed files with 14 additions and 3 deletions

View File

@ -5,8 +5,8 @@ use GraphQL\Error\InvariantViolation;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\SelectionNode;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Schema;
use GraphQL\Utils;
@ -138,6 +138,8 @@ class ResolveInfo
$fragment = $this->fragments[$spreadName];
$fields += $this->foldSelectionSet($fragment->selectionSet, $descend);
}
} else if ($selectionNode instanceof InlineFragmentNode) {
$fields += $this->foldSelectionSet($selectionNode->selectionSet, $descend);
}
}

View File

@ -71,6 +71,7 @@ class ResolveInfoTest extends \PHPUnit_Framework_TestCase
image {
width
height
...MyImage
}
replies {
body
@ -80,6 +81,9 @@ class ResolveInfoTest extends \PHPUnit_Framework_TestCase
pic {
url
width
... on Image {
height
}
}
recentArticle {
id
@ -90,6 +94,9 @@ class ResolveInfoTest extends \PHPUnit_Framework_TestCase
}
}
}
fragment MyImage on Image {
url
}
';
$expectedDefaultSelection = [
'author' => true,
@ -106,7 +113,8 @@ class ResolveInfoTest extends \PHPUnit_Framework_TestCase
],
'image' => [
'width' => true,
'height' => true
'height' => true,
'url' => true
],
'replies' => [
'body' => true,
@ -115,7 +123,8 @@ class ResolveInfoTest extends \PHPUnit_Framework_TestCase
'name' => true,
'pic' => [
'url' => true,
'width' => true
'width' => true,
'height' => true
],
'recentArticle' => [
'id' => true,