@@ -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,7 +1090,7 @@ 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}.
1079
- - Set the entry for {maskingTargets } in {groupDetailsMap} to {details}.
1093
+ - Set the entry for {targets } in {groupDetailsMap} to {details}.
1080
1094
- Return {groupedFieldSet} and {groupDetailsMap}.
1081
1095
1082
1096
Note: entries are always added to Grouped Field Set records in the order in
@@ -1094,6 +1108,44 @@ GetOrderedResponseKeys(targets, fieldsByTarget):
1094
1108
1095
1109
GetTargetSetDetails(targetsByKey, parentTargets):
1096
1110
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
+
1097
1149
- Initialize {keysWithParentTargets} to the empty set.
1098
1150
- Initialize {targetSetDetailsMap} to an empty unordered map.
1099
1151
- For each {responseKey} and {targets} in {targetsByKey}:
@@ -1125,7 +1177,7 @@ GetTargetSetDetails(targetsByKey, parentTargets):
1125
1177
- Set {shouldInitiateDefer} equal to {true}.
1126
1178
- Create {newTargetSetDetails} as an map containing {keys} and
1127
1179
{shouldInitiateDefer}.
1128
- - Set the entry in {targetSetDetailsMap} for {maskingTargets } to
1180
+ - Set the entry in {targetSetDetailsMap} for {targets } to
1129
1181
{newTargetSetDetails}.
1130
1182
- Return {keysWithParentTargets} and {targetSetDetailsMap}.
1131
1183
@@ -1138,6 +1190,15 @@ IsSameSet(setA, setB):
1138
1190
- Return {false}.
1139
1191
- Return {true}.
1140
1192
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
+
1141
1202
## Executing Deferred Grouped Field Sets
1142
1203
1143
1204
ExecuteDeferredGroupedFieldSets(objectType, objectValue, variableValues, path,
0 commit comments