@@ -494,12 +494,9 @@ The depth-first-search order of the field groups produced by {CollectFields()}
494494is maintained through execution, ensuring that fields appear in the executed
495495response in a stable and predictable order.
496496
497- CollectFields(objectType, selectionSet, variableValues, groupedFieldSet,
498- visitedFragments):
497+ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
499498
500- - If {groupedFieldSet} is not provided, initialize it an empty ordered map of
501- lists.
502- - If {visitedFragments} is not provided, initialize it to the empty set.
499+ - Initialize {groupedFieldSet} to an empty ordered map of lists.
503500- For each {selection} in {selectionSet}:
504501 - If {selection} provides the directive ` @skip ` , let {skipDirective} be that
505502 directive.
@@ -530,16 +527,31 @@ visitedFragments):
530527 - If {DoesFragmentTypeApply(objectType, fragmentType)} is false, continue
531528 with the next {selection} in {selectionSet}.
532529 - Let {fragmentSelectionSet} be the top-level selection set of {fragment}.
533- - Call {CollectFields(objectType, fragmentSelectionSet, variableValues,
534- groupedFieldSet, visitedFragments)}.
530+ - Let {fragmentGroupedFieldSet} be the result of calling
531+ {CollectFields(objectType, fragmentSelectionSet, variableValues,
532+ visitedFragments)}.
533+ - For each {fragmentGroup} in {fragmentGroupedFieldSet}:
534+ - Let {responseKey} be the response key shared by all fields in
535+ {fragmentGroup}.
536+ - Let {groupForResponseKey} be the list in {groupedFieldSet} for
537+ {responseKey}; if no such list exists, create it as an empty list.
538+ - Append all items in {fragmentGroup} to {groupForResponseKey}.
535539 - If {selection} is an {InlineFragment}:
536540 - Let {fragmentType} be the type condition on {selection}.
537541 - If {fragmentType} is not {null} and {DoesFragmentTypeApply(objectType,
538542 fragmentType)} is false, continue with the next {selection} in
539543 {selectionSet}.
540544 - Let {fragmentSelectionSet} be the top-level selection set of {selection}.
541- - Call {CollectFields(objectType, fragmentSelectionSet, variableValues,
542- groupedFieldSet, visitedFragments)}.
545+ - Let {fragmentGroupedFieldSet} be the result of calling
546+ {CollectFields(objectType, fragmentSelectionSet, variableValues,
547+ visitedFragments)}.
548+ - For each {fragmentGroup} in {fragmentGroupedFieldSet}:
549+ - Let {responseKey} be the response key shared by all fields in
550+ {fragmentGroup}.
551+ - Let {groupForResponseKey} be the list in {groupedFieldSet} for
552+ {responseKey}; if no such list exists, create it as an empty list.
553+ - Append all items in {fragmentGroup} to {groupForResponseKey}.
554+ - Return {groupedFields} and {visitedFragments}.
543555
544556DoesFragmentTypeApply(objectType, fragmentType):
545557
@@ -562,9 +574,9 @@ Root field collection processes the operation's top-level selection set:
562574
563575CollectRootFields(rootType, operationSelectionSet, variableValues):
564576
565- - Initialize {groupedFieldSet } to an empty ordered map of lists .
566- - Call { CollectFields(rootType, operationSelectionSet, variableValues
567- groupedFieldSet )}.
577+ - Initialize {visitedFragments } to the empty set .
578+ - Let {groupedFieldSet} be the result of calling { CollectFields(rootType,
579+ operationSelectionSet, variableValues, visitedFragments )}.
568580- Return {groupedFieldSet}.
569581
570582### Object Subfield Collection
@@ -573,12 +585,22 @@ Object subfield collection processes a field's sub-selection sets:
573585
574586CollectSubfields(objectType, fields, variableValues):
575587
588+ - Initialize {visitedFragments} to the empty set.
576589- Initialize {groupedSubfieldSet} to an empty ordered map of lists.
577590- For each {field} in {fields}:
578591 - Let {fieldSelectionSet} be the selection set of {field}.
579592 - If {fieldSelectionSet} is null or empty, continue to the next field.
580- - Call {CollectFields(objectType, fieldSelectionSet, variableValues,
581- groupedSubfieldSet)}.
593+ - Let {fieldGroupedFieldSet} and {fieldVisitedFragments} be the result of
594+ calling {CollectFields(objectType, fragmentSelectionSet, variableValues,
595+ visitedFragments)}.
596+ - For each {fieldGroup} in {fieldGroupedFieldSet}:
597+ - Let {responseKey} be the response key shared by all fields in
598+ {fragmentGroup}.
599+ - Let {groupForResponseKey} be the list in {groupedFieldSet} for
600+ {responseKey}; if no such list exists, create it as an empty list.
601+ - Append all items in {fieldGroup} to {groupForResponseKey}.
602+ - For each {fragmentSpreadName} in {fieldVisitedFragments}:
603+ - Add {fragmentSpreadName} to {visitedFragments}.
582604- Return {groupedSubfieldSet}.
583605
584606## Executing Fields
0 commit comments