@@ -164,59 +164,61 @@ private function analyzeSelectionSet(SelectionSetNode $selectionSet, Type $paren
164164 {
165165 $ fields = [];
166166 $ 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 ;
170170
171171 if ($ fieldName === Introspection::TYPE_NAME_FIELD_NAME ) {
172172 continue ;
173173 }
174174
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 ' );
176176
177177 $ type = $ parentType ->getField ($ fieldName );
178178 $ selectionType = $ type ->getType ();
179179
180- $ subfields = [];
181180 $ 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 );
185185
186186 $ fields [$ fieldName ] = [
187187 'type ' => $ selectionType ,
188188 'fields ' => $ subfields ,
189- 'args ' => Values::getArgumentValues ($ type , $ selectionNode , $ this ->variableValues ),
189+ 'args ' => Values::getArgumentValues ($ type , $ selection , $ this ->variableValues ),
190190 ];
191191 if ($ this ->groupImplementorFields && $ subImplementors ) {
192192 $ fields [$ fieldName ]['implementors ' ] = $ subImplementors ;
193193 }
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 ;
203199 }
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 ;
206208 $ type = $ typeCondition === null
207209 ? $ parentType
208210 : $ this ->schema ->getType ($ typeCondition ->name ->value );
209211 assert ($ type instanceof Type, 'ensured by query validation ' );
210212
211- $ subfields = $ this ->analyzeSubFields ($ type , $ selectionNode ->selectionSet );
213+ $ subfields = $ this ->analyzeSubFields ($ type , $ selection ->selectionSet );
212214 $ fields = $ this ->mergeFields ($ parentType , $ type , $ fields , $ subfields , $ implementors );
213215 }
214216 }
215217
216218 $ parentTypeName = $ parentType ->name ();
217219
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.
220222 $ this ->typeToFields [$ parentTypeName ] ??= [];
221223 foreach ($ fields as $ fieldName => $ _ ) {
222224 $ this ->typeToFields [$ parentTypeName ][$ fieldName ] = true ;
0 commit comments