@@ -494,12 +494,9 @@ The depth-first-search order of the field groups produced by {CollectFields()}
494
494
is maintained through execution, ensuring that fields appear in the executed
495
495
response in a stable and predictable order.
496
496
497
- CollectFields(objectType, selectionSet, variableValues, groupedFieldSet,
498
- visitedFragments):
497
+ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
499
498
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.
503
500
- For each {selection} in {selectionSet}:
504
501
- If {selection} provides the directive ` @skip ` , let {skipDirective} be that
505
502
directive.
@@ -530,16 +527,31 @@ visitedFragments):
530
527
- If {DoesFragmentTypeApply(objectType, fragmentType)} is false, continue
531
528
with the next {selection} in {selectionSet}.
532
529
- 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}.
535
539
- If {selection} is an {InlineFragment}:
536
540
- Let {fragmentType} be the type condition on {selection}.
537
541
- If {fragmentType} is not {null} and {DoesFragmentTypeApply(objectType,
538
542
fragmentType)} is false, continue with the next {selection} in
539
543
{selectionSet}.
540
544
- 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}.
543
555
544
556
DoesFragmentTypeApply(objectType, fragmentType):
545
557
@@ -562,9 +574,9 @@ Root field collection processes the operation's top-level selection set:
562
574
563
575
CollectRootFields(rootType, operationSelectionSet, variableValues):
564
576
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 )}.
568
580
- Return {groupedFieldSet}.
569
581
570
582
### Object Subfield Collection
@@ -573,12 +585,22 @@ Object subfield collection processes a field's sub-selection sets:
573
585
574
586
CollectSubfields(objectType, fields, variableValues):
575
587
588
+ - Initialize {visitedFragments} to the empty set.
576
589
- Initialize {groupedSubfieldSet} to an empty ordered map of lists.
577
590
- For each {field} in {fields}:
578
591
- Let {fieldSelectionSet} be the selection set of {field}.
579
592
- 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}.
582
604
- Return {groupedSubfieldSet}.
583
605
584
606
## Executing Fields
0 commit comments