@@ -1036,16 +1036,30 @@ BuildGroupedFieldSets(fieldsByTarget, targetsByKey, parentTargets)
1036
1036
1037
1037
- If {parentTargets} is not provided, initialize it to a set containing the
1038
1038
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}.
1039
1047
- 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}.
1043
1054
- Let {fieldGroup} be the Field Group record in {groupedFieldSet} for
1044
1055
{responseKey}; if no such record exists, create a new such record from the
1045
1056
empty list {fields} and the set of {parentTargets}.
1057
+ - Let {targets} be the entry in {targetsByKeys} for {responseKey}.
1046
1058
- 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}.
1049
1063
- For each {node} of {nodes}:
1050
1064
- Let {fieldDetails} be a new Field Details record created from {node}
1051
1065
and {target}.
@@ -1076,6 +1090,44 @@ BuildGroupedFieldSets(fieldsByTarget, targetsByKey, parentTargets)
1076
1090
- Initialize {details} to an empty unordered map.
1077
1091
- Set the entry for {groupedFieldSet} in {details} to {newGroupedFieldSet}.
1078
1092
- 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}.
1079
1131
- Set the entry for {maskingTargets} in {groupDetailsMap} to {details}.
1080
1132
- Return {groupedFieldSet} and {groupDetailsMap}.
1081
1133
@@ -1116,7 +1168,7 @@ GetTargetSetDetails(targetsByKey, parentTargets):
1116
1168
- Set {shouldInitiateDefer} equal to {true}.
1117
1169
- Create {newTargetSetDetails} as an map containing {keys} and
1118
1170
{shouldInitiateDefer}.
1119
- - Set the entry in {targetSetDetailsMap} for {maskingTargets } to
1171
+ - Set the entry in {targetSetDetailsMap} for {targets } to
1120
1172
{newTargetSetDetails}.
1121
1173
- Return {keysWithParentTargets} and {targetSetDetailsMap}.
1122
1174
@@ -1129,6 +1181,15 @@ IsSameSet(setA, setB):
1129
1181
- Return {false}.
1130
1182
- Return {true}.
1131
1183
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
+
1132
1193
## Executing Deferred Grouped Field Sets
1133
1194
1134
1195
ExecuteDeferredGroupedFieldSets(objectType, objectValue, variableValues, path,
0 commit comments