@@ -164,59 +164,61 @@ private function analyzeSelectionSet(SelectionSetNode $selectionSet, Type $paren
164
164
{
165
165
$ fields = [];
166
166
$ implementors = [];
167
- foreach ($ selectionSet ->selections as $ selectionNode ) {
168
- if ($ selectionNode instanceof FieldNode) {
169
- $ fieldName = $ selectionNode ->name ->value ;
167
+ foreach ($ selectionSet ->selections as $ selection ) {
168
+ if ($ selection instanceof FieldNode) {
169
+ $ fieldName = $ selection ->name ->value ;
170
170
171
171
if ($ fieldName === Introspection::TYPE_NAME_FIELD_NAME ) {
172
172
continue ;
173
173
}
174
174
175
- assert ($ parentType instanceof HasFieldsType, 'ensured by query validation and the check above which excludes union types ' );
175
+ assert ($ parentType instanceof HasFieldsType, 'ensured by query validation ' );
176
176
177
177
$ type = $ parentType ->getField ($ fieldName );
178
178
$ selectionType = $ type ->getType ();
179
179
180
- $ subfields = [];
181
180
$ subImplementors = [];
182
- if (isset ($ selectionNode ->selectionSet )) {
183
- $ subfields = $ this ->analyzeSubFields ($ selectionType , $ selectionNode ->selectionSet , $ subImplementors );
184
- }
181
+ $ nestedSelectionSet = $ selection ->selectionSet ;
182
+ $ subfields = $ nestedSelectionSet === null
183
+ ? []
184
+ : $ this ->analyzeSubFields ($ selectionType , $ nestedSelectionSet , $ subImplementors );
185
185
186
186
$ fields [$ fieldName ] = [
187
187
'type ' => $ selectionType ,
188
188
'fields ' => $ subfields ,
189
- 'args ' => Values::getArgumentValues ($ type , $ selectionNode , $ this ->variableValues ),
189
+ 'args ' => Values::getArgumentValues ($ type , $ selection , $ this ->variableValues ),
190
190
];
191
191
if ($ this ->groupImplementorFields && $ subImplementors ) {
192
192
$ fields [$ fieldName ]['implementors ' ] = $ subImplementors ;
193
193
}
194
- } elseif ($ selectionNode instanceof FragmentSpreadNode) {
195
- $ spreadName = $ selectionNode ->name ->value ;
196
- if (isset ($ this ->fragments [$ spreadName ])) {
197
- $ fragment = $ this ->fragments [$ spreadName ];
198
- $ type = $ this ->schema ->getType ($ fragment ->typeCondition ->name ->value );
199
- assert ($ type instanceof Type, 'ensured by query validation ' );
200
-
201
- $ subfields = $ this ->analyzeSubFields ($ type , $ fragment ->selectionSet );
202
- $ fields = $ this ->mergeFields ($ parentType , $ type , $ fields , $ subfields , $ implementors );
194
+ } elseif ($ selection instanceof FragmentSpreadNode) {
195
+ $ spreadName = $ selection ->name ->value ;
196
+ $ fragment = $ this ->fragments [$ spreadName ] ?? null ;
197
+ if ($ fragment === null ) {
198
+ continue ;
203
199
}
204
- } elseif ($ selectionNode instanceof InlineFragmentNode) {
205
- $ typeCondition = $ selectionNode ->typeCondition ;
200
+
201
+ $ type = $ this ->schema ->getType ($ fragment ->typeCondition ->name ->value );
202
+ assert ($ type instanceof Type, 'ensured by query validation ' );
203
+
204
+ $ subfields = $ this ->analyzeSubFields ($ type , $ fragment ->selectionSet );
205
+ $ fields = $ this ->mergeFields ($ parentType , $ type , $ fields , $ subfields , $ implementors );
206
+ } elseif ($ selection instanceof InlineFragmentNode) {
207
+ $ typeCondition = $ selection ->typeCondition ;
206
208
$ type = $ typeCondition === null
207
209
? $ parentType
208
210
: $ this ->schema ->getType ($ typeCondition ->name ->value );
209
211
assert ($ type instanceof Type, 'ensured by query validation ' );
210
212
211
- $ subfields = $ this ->analyzeSubFields ($ type , $ selectionNode ->selectionSet );
213
+ $ subfields = $ this ->analyzeSubFields ($ type , $ selection ->selectionSet );
212
214
$ fields = $ this ->mergeFields ($ parentType , $ type , $ fields , $ subfields , $ implementors );
213
215
}
214
216
}
215
217
216
218
$ parentTypeName = $ parentType ->name ();
217
219
218
- // TODO evaluate if this line is really necessary - it causes abstract types to appear
219
- // in getReferencedTypes() even if they do not have any fields directly referencing them.
220
+ // TODO evaluate if this line is really necessary.
221
+ // It causes abstract types to appear in getReferencedTypes() even if they do not have any fields directly referencing them.
220
222
$ this ->typeToFields [$ parentTypeName ] ??= [];
221
223
foreach ($ fields as $ fieldName => $ _ ) {
222
224
$ this ->typeToFields [$ parentTypeName ][$ fieldName ] = true ;
0 commit comments