Skip to content

Commit fd2eb74

Browse files
robrichardyaacovCR
authored andcommitted
Align deferred fragment field collection with reference implementation
1 parent 597eb6c commit fd2eb74

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

spec/Section 6 -- Execution.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,9 @@ subsequentPayloads, asyncRecord):
410410

411411
- If {path} is not provided, initialize it to an empty list.
412412
- If {subsequentPayloads} is not provided, initialize it to the empty set.
413-
- Let {groupedFieldSet} be the result of {CollectFields(objectType, objectValue,
414-
selectionSet, variableValues, path subsequentPayloads, asyncRecord)}.
413+
- Let {groupedFieldSet} and {deferredGroupedFieldsList} be the result of
414+
{CollectFields(objectType, objectValue, selectionSet, variableValues, path,
415+
asyncRecord)}.
415416
- Initialize {resultMap} to an empty ordered map.
416417
- For each {groupedFieldSet} as {responseKey} and {fields}:
417418
- Let {fieldName} be the name of the first entry in {fields}. Note: This value
@@ -422,6 +423,10 @@ subsequentPayloads, asyncRecord):
422423
- Let {responseValue} be {ExecuteField(objectType, objectValue, fieldType,
423424
fields, variableValues, path, subsequentPayloads, asyncRecord)}.
424425
- Set {responseValue} as the value for {responseKey} in {resultMap}.
426+
- For each {deferredGroupFieldSet} and {label} in {deferredGroupedFieldsList}
427+
- Call {ExecuteDeferredFragment(label, objectType, objectValue,
428+
deferredGroupFieldSet, path, variableValues, asyncRecord,
429+
subsequentPayloads)}
425430
- Return {resultMap}.
426431

427432
Note: {resultMap} is ordered by which fields appear first in the operation. This
@@ -573,10 +578,12 @@ is maintained through execution, ensuring that fields appear in the executed
573578
response in a stable and predictable order.
574579

575580
CollectFields(objectType, objectValue, selectionSet, variableValues, path,
576-
subsequentPayloads, asyncRecord, visitedFragments):
581+
asyncRecord, visitedFragments, deferredGroupedFieldsList):
577582

578583
- If {visitedFragments} is not provided, initialize it to the empty set.
579584
- Initialize {groupedFields} to an empty ordered map of lists.
585+
- If {deferredGroupedFieldsList} is not provided, initialize it to an empty
586+
list.
580587
- For each {selection} in {selectionSet}:
581588
- If {selection} provides the directive `@skip`, let {skipDirective} be that
582589
directive.
@@ -615,13 +622,17 @@ subsequentPayloads, asyncRecord, visitedFragments):
615622
- If {deferDirective} is defined:
616623
- Let {label} be the value or the variable to {deferDirective}'s {label}
617624
argument.
618-
- Call {ExecuteDeferredFragment(label, objectType, objectValue,
619-
fragmentSelectionSet, path, variableValues, asyncRecord,
620-
subsequentPayloads)}.
625+
- Let {deferredGroupedFields} be the result of calling
626+
{CollectFields(objectType, objectValue, fragmentSelectionSet,
627+
variableValues, path, asyncRecord, visitedFragments,
628+
deferredGroupedFieldsList)}.
629+
- Append a record containing {label} and {deferredGroupedFields} to
630+
{deferredGroupedFieldsList}.
621631
- Continue with the next {selection} in {selectionSet}.
622632
- Let {fragmentGroupedFieldSet} be the result of calling
623633
{CollectFields(objectType, objectValue, fragmentSelectionSet,
624-
variableValues, path, subsequentPayloads, asyncRecord, visitedFragments)}.
634+
variableValues, path, asyncRecord, visitedFragments,
635+
deferredGroupedFieldsList)}.
625636
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
626637
- Let {responseKey} be the response key shared by all fields in
627638
{fragmentGroup}.
@@ -640,19 +651,24 @@ subsequentPayloads, asyncRecord, visitedFragments):
640651
{variableValues} with the value {true}:
641652
- Let {label} be the value or the variable to {deferDirective}'s {label}
642653
argument.
643-
- Call {ExecuteDeferredFragment(label, objectType, objectValue,
644-
fragmentSelectionSet, path, asyncRecord, subsequentPayloads)}.
654+
- Let {deferredGroupedFields} be the result of calling
655+
{CollectFields(objectType, objectValue, fragmentSelectionSet,
656+
variableValues, path, asyncRecord, visitedFragments,
657+
deferredGroupedFieldsList)}.
658+
- Append a record containing {label} and {deferredGroupedFields} to
659+
{deferredGroupedFieldsList}.
645660
- Continue with the next {selection} in {selectionSet}.
646661
- Let {fragmentGroupedFieldSet} be the result of calling
647662
{CollectFields(objectType, objectValue, fragmentSelectionSet,
648-
variableValues, path, subsequentPayloads, asyncRecord, visitedFragments)}.
663+
variableValues, path, asyncRecord, visitedFragments,
664+
deferredGroupedFieldsList)}.
649665
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
650666
- Let {responseKey} be the response key shared by all fields in
651667
{fragmentGroup}.
652668
- Let {groupForResponseKey} be the list in {groupedFields} for
653669
{responseKey}; if no such list exists, create it as an empty list.
654670
- Append all items in {fragmentGroup} to {groupForResponseKey}.
655-
- Return {groupedFields}.
671+
- Return {groupedFields} and {deferredGroupedFieldsList}.
656672

657673
Note: The steps in {CollectFields()} evaluating the `@skip` and `@include`
658674
directives may be applied in either order since they apply commutatively.
@@ -686,22 +702,29 @@ All Async Payload Records are structures containing:
686702

687703
#### Execute Deferred Fragment
688704

689-
ExecuteDeferredFragment(label, objectType, objectValue, fragmentSelectionSet,
690-
path, variableValues, parentRecord, subsequentPayloads):
705+
ExecuteDeferredFragment(label, objectType, objectValue, groupedFieldSet, path,
706+
variableValues, parentRecord, subsequentPayloads):
691707

692708
- Let {deferRecord} be an async payload record created from {label} and {path}.
693709
- Initialize {errors} on {deferRecord} to an empty list.
694710
- Let {dataExecution} be the asynchronous future value of:
695711
- Let {payload} be an unordered map.
696-
- Let {data} be the result of {ExecuteSelectionSet(fragmentSelectionSet,
697-
objectType, objectValue, variableValues, path, subsequentPayloads,
698-
deferRecord)}.
712+
- Initialize {resultMap} to an empty ordered map.
713+
- For each {groupedFieldSet} as {responseKey} and {fields}:
714+
- Let {fieldName} be the name of the first entry in {fields}. Note: This
715+
value is unaffected if an alias is used.
716+
- Let {fieldType} be the return type defined for the field {fieldName} of
717+
{objectType}.
718+
- If {fieldType} is defined:
719+
- Let {responseValue} be {ExecuteField(objectType, objectValue, fieldType,
720+
fields, variableValues, path, subsequentPayloads, asyncRecord)}.
721+
- Set {responseValue} as the value for {responseKey} in {resultMap}.
699722
- Append any encountered field errors to {errors}.
700723
- If {parentRecord} is defined:
701724
- Wait for the result of {dataExecution} on {parentRecord}.
702725
- If {errors} is not empty:
703726
- Add an entry to {payload} named `errors` with the value {errors}.
704-
- Add an entry to {payload} named `data` with the value {data}.
727+
- Add an entry to {payload} named `data` with the value {resultMap}.
705728
- Add an entry to {payload} named `label` with the value {label}.
706729
- Add an entry to {payload} named `path` with the value {path}.
707730
- Return {payload}.

0 commit comments

Comments
 (0)