@@ -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,7 +1090,7 @@ 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}.
1079- - Set the entry for {maskingTargets } in {groupDetailsMap} to {details}.
1093+ - Set the entry for {targets } in {groupDetailsMap} to {details}.
10801094- Return {groupedFieldSet} and {groupDetailsMap}.
10811095
10821096Note: entries are always added to Grouped Field Set records in the order in
@@ -1094,6 +1108,44 @@ GetOrderedResponseKeys(targets, fieldsByTarget):
10941108
10951109GetTargetSetDetails(targetsByKey, parentTargets):
10961110
1111+ - Initialize {keysWithParentTargets} to the empty set.
1112+ - Initialize {targetSetDetailsMap} to an empty unordered map.
1113+ - For each {responseKey} and {targets} in {targetsByKey}:
1114+ - If {IsSameSet(targets, parentTargets)} is {true}:
1115+ - Append {responseKey} to {keysWithParentTargets}.
1116+ - Continue to the next entry in {targetsByKey}.
1117+ - For each {key} in {targetSetDetailsMap}:
1118+ - If {IsSameSet(targets, key)} is {true}, let {targetSetDetails} be the map
1119+ in {targetSetDetailsMap} for {targets}.
1120+ - If {targetSetDetails} is defined:
1121+ - Let {keys} be the corresponding entry on {targetSetDetails}.
1122+ - Add {responseKey} to {keys}.
1123+ - Otherwise:
1124+ - Initialize {keys} to the empty set.
1125+ - Add {responseKey} to {keys}.
1126+ - Let {shouldInitiateDefer} be {false}.
1127+ - For each {target} in {targets}:
1128+ - Let {remainingFieldsForTarget} be the entry in {remainingFieldsByTarget}
1129+ for {target}.
1130+ - Let {nodes} be the list in {remainingFieldsByTarget} for {responseKey}.
1131+ - Remove the entry for {responseKey} from {remainingFieldsByTarget}.
1132+ - For each {node} of {nodes}:
1133+ - Let {fieldDetails} be a new Field Details record created from {node}
1134+ and {target}.
1135+ - Append {fieldDetails} to the {fields} entry on {fieldGroup}.
1136+ - Let {shouldInitiateDefer} be the corresponding entry on {targetSetDetails}.
1137+ - Initialize {details} to an empty unordered map.
1138+ - Set the entry for {groupedFieldSet} in {details} to {newGroupedFieldSet}.
1139+ - Set the corresponding entry in {details} to {shouldInitiateDefer}.
1140+ - Set the entry for {maskingTargets} in {groupDetailsMap} to {details}.
1141+ - Return {groupedFieldSet} and {groupDetailsMap}.
1142+
1143+ Note: entries are always added to Grouped Field Set records in the order in
1144+ which they appear for the first target. Field order for deferred grouped field
1145+ sets never alters the field order for the parent.
1146+
1147+ GetTargetSetDetails(targetsByKey, parentTargets):
1148+
10971149- Initialize {keysWithParentTargets} to the empty set.
10981150- Initialize {targetSetDetailsMap} to an empty unordered map.
10991151- For each {responseKey} and {targets} in {targetsByKey}:
@@ -1125,7 +1177,7 @@ GetTargetSetDetails(targetsByKey, parentTargets):
11251177 - Set {shouldInitiateDefer} equal to {true}.
11261178 - Create {newTargetSetDetails} as an map containing {keys} and
11271179 {shouldInitiateDefer}.
1128- - Set the entry in {targetSetDetailsMap} for {maskingTargets } to
1180+ - Set the entry in {targetSetDetailsMap} for {targets } to
11291181 {newTargetSetDetails}.
11301182- Return {keysWithParentTargets} and {targetSetDetailsMap}.
11311183
@@ -1138,6 +1190,15 @@ IsSameSet(setA, setB):
11381190 - Return {false}.
11391191- Return {true}.
11401192
1193+ GetOrderedResponseKeys(targets, fieldsByTarget):
1194+
1195+ - Let {firstTarget} be the first entry in {targets}.
1196+ - Assert that {firstTarget} is defined.
1197+ - Let {firstFields} be the entry for {firstTarget} in {fieldsByTarget}.
1198+ - Assert that {firstFields} is defined.
1199+ - Let {responseKeys} be the keys of {firstFields}.
1200+ - Return {responseKeys}.
1201+
11411202## Executing Deferred Grouped Field Sets
11421203
11431204ExecuteDeferredGroupedFieldSets(objectType, objectValue, variableValues, path,
0 commit comments