Skip to content

Commit f4ad226

Browse files
committed
deferred fields should not change ordering of non-deferred
1 parent ab1f373 commit f4ad226

File tree

1 file changed

+67
-6
lines changed

1 file changed

+67
-6
lines changed

spec/Section 6 -- Execution.md

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,16 +1036,30 @@ BuildGroupedFieldSets(fieldsByTarget, targetsByKey, parentTargets)
10361036

10371037
- If {parentTargets} is not provided, initialize it to a set containing the
10381038
value {undefined}.
1039+
- Let {keysWithParentTargets} and {targetSetDetailsMap} be the result of
1040+
{GetTargetSetDetails(targetsByKey, parentTargets)}.
1041+
- Initialize {remainingFieldsByTarget} to an empty unordered map of ordered
1042+
maps.
1043+
- For each {target} and {fieldsForTarget} in {fieldsByTarget}:
1044+
- Initialize {remainingFieldsForTarget} to an empty ordered map.
1045+
- For each {responseKey} and {fieldList} in {fieldsForTarget}:
1046+
- Set {responseKey} on {remainingFieldsForTarget} to {fieldList}.
10391047
- Initialize {groupedFieldSet} to an empty ordered map.
1040-
- Initialize {groupDetailsMap} to an empty unordered map.
1041-
- For each {responseKey} and {targets} in {targetsByKey}:
1042-
- If {IsSameSet(targets, parentTargets)} is {true}:
1048+
- If {keysWithParentTargets} is not empty:
1049+
- Let {orderedResponseKeys} be the result of
1050+
{GetOrderedResponseKeys(parentTargets, remainingFieldsByTarget)}.
1051+
- For each {responseKey} in {orderedResponseKeys}:
1052+
- If {keysWithParentTargets} does not contain {responseKey}, continue to the
1053+
next member of {orderedResponseKeys}.
10431054
- Let {fieldGroup} be the Field Group record in {groupedFieldSet} for
10441055
{responseKey}; if no such record exists, create a new such record from the
10451056
empty list {fields} and the set of {parentTargets}.
1057+
- Let {targets} be the entry in {targetsByKeys} for {responseKey}.
10461058
- For each {target} in {targets}:
1047-
- Let {fields} be the entry in {fieldsByTarget} for {target}.
1048-
- Let {nodes} be the list in {fields} for {responseKey}.
1059+
- Let {remainingFieldsForTarget} be the entry in {remainingFieldsByTarget}
1060+
for {target}.
1061+
- Let {nodes} be the list in {remainingFieldsByTarget} for {responseKey}.
1062+
- Remove the entry for {responseKey} from {remainingFieldsByTarget}.
10491063
- For each {node} of {nodes}:
10501064
- Let {fieldDetails} be a new Field Details record created from {node}
10511065
and {target}.
@@ -1076,6 +1090,44 @@ BuildGroupedFieldSets(fieldsByTarget, targetsByKey, parentTargets)
10761090
- Initialize {details} to an empty unordered map.
10771091
- Set the entry for {groupedFieldSet} in {details} to {newGroupedFieldSet}.
10781092
- Set the corresponding entry in {details} to {shouldInitiateDefer}.
1093+
- Set the entry for {targets} in {groupDetailsMap} to {details}.
1094+
- Return {groupedFieldSet} and {groupDetailsMap}.
1095+
1096+
Note: entries are always added to Grouped Field Set records in the order in
1097+
which they appear for the first target. Field order for deferred grouped field
1098+
sets never alters the field order for the parent.
1099+
1100+
GetTargetSetDetails(targetsByKey, parentTargets):
1101+
1102+
- Initialize {keysWithParentTargets} to the empty set.
1103+
- Initialize {targetSetDetailsMap} to an empty unordered map.
1104+
- For each {responseKey} and {targets} in {targetsByKey}:
1105+
- If {IsSameSet(targets, parentTargets)} is {true}:
1106+
- Append {responseKey} to {keysWithParentTargets}.
1107+
- Continue to the next entry in {targetsByKey}.
1108+
- For each {key} in {targetSetDetailsMap}:
1109+
- If {IsSameSet(targets, key)} is {true}, let {targetSetDetails} be the map
1110+
in {targetSetDetailsMap} for {targets}.
1111+
- If {targetSetDetails} is defined:
1112+
- Let {keys} be the corresponding entry on {targetSetDetails}.
1113+
- Add {responseKey} to {keys}.
1114+
- Otherwise:
1115+
- Initialize {keys} to the empty set.
1116+
- Add {responseKey} to {keys}.
1117+
- Let {shouldInitiateDefer} be {false}.
1118+
- For each {target} in {targets}:
1119+
- Let {remainingFieldsForTarget} be the entry in {remainingFieldsByTarget}
1120+
for {target}.
1121+
- Let {nodes} be the list in {remainingFieldsByTarget} for {responseKey}.
1122+
- Remove the entry for {responseKey} from {remainingFieldsByTarget}.
1123+
- For each {node} of {nodes}:
1124+
- Let {fieldDetails} be a new Field Details record created from {node}
1125+
and {target}.
1126+
- Append {fieldDetails} to the {fields} entry on {fieldGroup}.
1127+
- Let {shouldInitiateDefer} be the corresponding entry on {targetSetDetails}.
1128+
- Initialize {details} to an empty unordered map.
1129+
- Set the entry for {groupedFieldSet} in {details} to {newGroupedFieldSet}.
1130+
- Set the corresponding entry in {details} to {shouldInitiateDefer}.
10791131
- Set the entry for {maskingTargets} in {groupDetailsMap} to {details}.
10801132
- Return {groupedFieldSet} and {groupDetailsMap}.
10811133

@@ -1116,7 +1168,7 @@ GetTargetSetDetails(targetsByKey, parentTargets):
11161168
- Set {shouldInitiateDefer} equal to {true}.
11171169
- Create {newTargetSetDetails} as an map containing {keys} and
11181170
{shouldInitiateDefer}.
1119-
- Set the entry in {targetSetDetailsMap} for {maskingTargets} to
1171+
- Set the entry in {targetSetDetailsMap} for {targets} to
11201172
{newTargetSetDetails}.
11211173
- Return {keysWithParentTargets} and {targetSetDetailsMap}.
11221174

@@ -1129,6 +1181,15 @@ IsSameSet(setA, setB):
11291181
- Return {false}.
11301182
- Return {true}.
11311183

1184+
GetOrderedResponseKeys(targets, fieldsByTarget):
1185+
1186+
- Let {firstTarget} be the first entry in {targets}.
1187+
- Assert that {firstTarget} is defined.
1188+
- Let {firstFields} be the entry for {firstTarget} in {fieldsByTarget}.
1189+
- Assert that {firstFields} is defined.
1190+
- Let {responseKeys} be the keys of {firstFields}.
1191+
- Return {responseKeys}.
1192+
11321193
## Executing Deferred Grouped Field Sets
11331194

11341195
ExecuteDeferredGroupedFieldSets(objectType, objectValue, variableValues, path,

0 commit comments

Comments
 (0)