Skip to content

Commit

Permalink
ResolveInfo: Take in account inline fragments in getFieldSelection()
Browse files Browse the repository at this point in the history
  • Loading branch information
vladar committed Mar 10, 2017
1 parent 827bfa7 commit f77bd17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Type/Definition/ResolveInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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;
Expand Down Expand Up @@ -138,6 +138,8 @@ private function foldSelectionSet(SelectionSetNode $selectionSet, $descend)
$fragment = $this->fragments[$spreadName];
$fields += $this->foldSelectionSet($fragment->selectionSet, $descend);
}
} else if ($selectionNode instanceof InlineFragmentNode) {
$fields += $this->foldSelectionSet($selectionNode->selectionSet, $descend);
}
}

Expand Down
13 changes: 11 additions & 2 deletions tests/Type/ResolveInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function testFieldSelection()
image {
width
height
...MyImage
}
replies {
body
Expand All @@ -80,6 +81,9 @@ public function testFieldSelection()
pic {
url
width
... on Image {
height
}
}
recentArticle {
id
Expand All @@ -90,6 +94,9 @@ public function testFieldSelection()
}
}
}
fragment MyImage on Image {
url
}
';
$expectedDefaultSelection = [
'author' => true,
Expand All @@ -106,7 +113,8 @@ public function testFieldSelection()
],
'image' => [
'width' => true,
'height' => true
'height' => true,
'url' => true
],
'replies' => [
'body' => true,
Expand All @@ -115,7 +123,8 @@ public function testFieldSelection()
'name' => true,
'pic' => [
'url' => true,
'width' => true
'width' => true,
'height' => true
],
'recentArticle' => [
'id' => true,
Expand Down

0 comments on commit f77bd17

Please sign in to comment.