Skip to content

Commit f77bd17

Browse files
committed
ResolveInfo: Take in account inline fragments in getFieldSelection()
1 parent 827bfa7 commit f77bd17

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Type/Definition/ResolveInfo.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use GraphQL\Language\AST\FieldNode;
66
use GraphQL\Language\AST\FragmentDefinitionNode;
77
use GraphQL\Language\AST\FragmentSpreadNode;
8+
use GraphQL\Language\AST\InlineFragmentNode;
89
use GraphQL\Language\AST\OperationDefinitionNode;
9-
use GraphQL\Language\AST\SelectionNode;
1010
use GraphQL\Language\AST\SelectionSetNode;
1111
use GraphQL\Schema;
1212
use GraphQL\Utils;
@@ -138,6 +138,8 @@ private function foldSelectionSet(SelectionSetNode $selectionSet, $descend)
138138
$fragment = $this->fragments[$spreadName];
139139
$fields += $this->foldSelectionSet($fragment->selectionSet, $descend);
140140
}
141+
} else if ($selectionNode instanceof InlineFragmentNode) {
142+
$fields += $this->foldSelectionSet($selectionNode->selectionSet, $descend);
141143
}
142144
}
143145

tests/Type/ResolveInfoTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function testFieldSelection()
7171
image {
7272
width
7373
height
74+
...MyImage
7475
}
7576
replies {
7677
body
@@ -80,6 +81,9 @@ public function testFieldSelection()
8081
pic {
8182
url
8283
width
84+
... on Image {
85+
height
86+
}
8387
}
8488
recentArticle {
8589
id
@@ -90,6 +94,9 @@ public function testFieldSelection()
9094
}
9195
}
9296
}
97+
fragment MyImage on Image {
98+
url
99+
}
93100
';
94101
$expectedDefaultSelection = [
95102
'author' => true,
@@ -106,7 +113,8 @@ public function testFieldSelection()
106113
],
107114
'image' => [
108115
'width' => true,
109-
'height' => true
116+
'height' => true,
117+
'url' => true
110118
],
111119
'replies' => [
112120
'body' => true,
@@ -115,7 +123,8 @@ public function testFieldSelection()
115123
'name' => true,
116124
'pic' => [
117125
'url' => true,
118-
'width' => true
126+
'width' => true,
127+
'height' => true
119128
],
120129
'recentArticle' => [
121130
'id' => true,

0 commit comments

Comments
 (0)