Skip to content

Commit a074400

Browse files
yaacovCRIvanGoncharov
authored andcommitted
use groupedFieldSet as variable name
to match type
1 parent 45f2a59 commit a074400

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

src/execution/collectFields.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export type GroupedFieldSet = Map<string, FieldGroup>;
3232

3333
export interface PatchFields {
3434
label: string | undefined;
35-
fields: GroupedFieldSet;
35+
groupedFieldSet: GroupedFieldSet;
3636
}
3737

3838
export interface FieldsAndPatches {
39-
fields: GroupedFieldSet;
39+
groupedFieldSet: GroupedFieldSet;
4040
patches: Array<PatchFields>;
4141
}
4242

@@ -56,7 +56,7 @@ export function collectFields(
5656
runtimeType: GraphQLObjectType,
5757
operation: OperationDefinitionNode,
5858
): FieldsAndPatches {
59-
const fields = new AccumulatorMap<string, FieldNode>();
59+
const groupedFieldSet = new AccumulatorMap<string, FieldNode>();
6060
const patches: Array<PatchFields> = [];
6161
collectFieldsImpl(
6262
schema,
@@ -65,11 +65,11 @@ export function collectFields(
6565
operation,
6666
runtimeType,
6767
operation.selectionSet,
68-
fields,
68+
groupedFieldSet,
6969
patches,
7070
new Set(),
7171
);
72-
return { fields, patches };
72+
return { groupedFieldSet, patches };
7373
}
7474

7575
/**
@@ -91,12 +91,12 @@ export function collectSubfields(
9191
returnType: GraphQLObjectType,
9292
fieldGroup: FieldGroup,
9393
): FieldsAndPatches {
94-
const subFieldNodes = new AccumulatorMap<string, FieldNode>();
94+
const subGroupedFieldSet = new AccumulatorMap<string, FieldNode>();
9595
const visitedFragmentNames = new Set<string>();
9696

9797
const subPatches: Array<PatchFields> = [];
9898
const subFieldsAndPatches = {
99-
fields: subFieldNodes,
99+
groupedFieldSet: subGroupedFieldSet,
100100
patches: subPatches,
101101
};
102102

@@ -109,7 +109,7 @@ export function collectSubfields(
109109
operation,
110110
returnType,
111111
node.selectionSet,
112-
subFieldNodes,
112+
subGroupedFieldSet,
113113
subPatches,
114114
visitedFragmentNames,
115115
);
@@ -126,7 +126,7 @@ function collectFieldsImpl(
126126
operation: OperationDefinitionNode,
127127
runtimeType: GraphQLObjectType,
128128
selectionSet: SelectionSetNode,
129-
fields: AccumulatorMap<string, FieldNode>,
129+
groupedFieldSet: AccumulatorMap<string, FieldNode>,
130130
patches: Array<PatchFields>,
131131
visitedFragmentNames: Set<string>,
132132
): void {
@@ -136,7 +136,7 @@ function collectFieldsImpl(
136136
if (!shouldIncludeNode(variableValues, selection)) {
137137
continue;
138138
}
139-
fields.add(getFieldEntryKey(selection), selection);
139+
groupedFieldSet.add(getFieldEntryKey(selection), selection);
140140
break;
141141
}
142142
case Kind.INLINE_FRAGMENT: {
@@ -164,7 +164,7 @@ function collectFieldsImpl(
164164
);
165165
patches.push({
166166
label: defer.label,
167-
fields: patchFields,
167+
groupedFieldSet: patchFields,
168168
});
169169
} else {
170170
collectFieldsImpl(
@@ -174,7 +174,7 @@ function collectFieldsImpl(
174174
operation,
175175
runtimeType,
176176
selection.selectionSet,
177-
fields,
177+
groupedFieldSet,
178178
patches,
179179
visitedFragmentNames,
180180
);
@@ -220,7 +220,7 @@ function collectFieldsImpl(
220220
);
221221
patches.push({
222222
label: defer.label,
223-
fields: patchFields,
223+
groupedFieldSet: patchFields,
224224
});
225225
} else {
226226
collectFieldsImpl(
@@ -230,7 +230,7 @@ function collectFieldsImpl(
230230
operation,
231231
runtimeType,
232232
fragment.selectionSet,
233-
fields,
233+
groupedFieldSet,
234234
patches,
235235
visitedFragmentNames,
236236
);

src/execution/execute.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ function executeOperation(
536536
);
537537
}
538538

539-
const { fields: rootFields, patches } = collectFields(
539+
const { groupedFieldSet, patches } = collectFields(
540540
schema,
541541
fragments,
542542
variableValues,
@@ -548,30 +548,42 @@ function executeOperation(
548548

549549
switch (operation.operation) {
550550
case OperationTypeNode.QUERY:
551-
result = executeFields(exeContext, rootType, rootValue, path, rootFields);
551+
result = executeFields(
552+
exeContext,
553+
rootType,
554+
rootValue,
555+
path,
556+
groupedFieldSet,
557+
);
552558
break;
553559
case OperationTypeNode.MUTATION:
554560
result = executeFieldsSerially(
555561
exeContext,
556562
rootType,
557563
rootValue,
558564
path,
559-
rootFields,
565+
groupedFieldSet,
560566
);
561567
break;
562568
case OperationTypeNode.SUBSCRIPTION:
563569
// TODO: deprecate `subscribe` and move all logic here
564570
// Temporary solution until we finish merging execute and subscribe together
565-
result = executeFields(exeContext, rootType, rootValue, path, rootFields);
571+
result = executeFields(
572+
exeContext,
573+
rootType,
574+
rootValue,
575+
path,
576+
groupedFieldSet,
577+
);
566578
}
567579

568580
for (const patch of patches) {
569-
const { label, fields: patchFields } = patch;
581+
const { label, groupedFieldSet: patchGroupedFieldSet } = patch;
570582
executeDeferredFragment(
571583
exeContext,
572584
rootType,
573585
rootValue,
574-
patchFields,
586+
patchGroupedFieldSet,
575587
label,
576588
path,
577589
);
@@ -1447,28 +1459,25 @@ function collectAndExecuteSubfields(
14471459
asyncPayloadRecord?: AsyncPayloadRecord,
14481460
): PromiseOrValue<ObjMap<unknown>> {
14491461
// Collect sub-fields to execute to complete this value.
1450-
const { fields: subFieldNodes, patches: subPatches } = collectSubfields(
1451-
exeContext,
1452-
returnType,
1453-
fieldGroup,
1454-
);
1462+
const { groupedFieldSet: subGroupedFieldSet, patches: subPatches } =
1463+
collectSubfields(exeContext, returnType, fieldGroup);
14551464

14561465
const subFields = executeFields(
14571466
exeContext,
14581467
returnType,
14591468
result,
14601469
path,
1461-
subFieldNodes,
1470+
subGroupedFieldSet,
14621471
asyncPayloadRecord,
14631472
);
14641473

14651474
for (const subPatch of subPatches) {
1466-
const { label, fields: subPatchFieldNodes } = subPatch;
1475+
const { label, groupedFieldSet: subPatchGroupedFieldSet } = subPatch;
14671476
executeDeferredFragment(
14681477
exeContext,
14691478
returnType,
14701479
result,
1471-
subPatchFieldNodes,
1480+
subPatchGroupedFieldSet,
14721481
label,
14731482
path,
14741483
asyncPayloadRecord,
@@ -1691,15 +1700,15 @@ function executeSubscription(
16911700
);
16921701
}
16931702

1694-
const { fields: rootFields } = collectFields(
1703+
const { groupedFieldSet } = collectFields(
16951704
schema,
16961705
fragments,
16971706
variableValues,
16981707
rootType,
16991708
operation,
17001709
);
17011710

1702-
const firstRootField = rootFields.entries().next().value;
1711+
const firstRootField = groupedFieldSet.entries().next().value;
17031712
const [responseName, fieldGroup] = firstRootField;
17041713
const fieldName = fieldGroup[0].name.value;
17051714
const fieldDef = schema.getField(rootType, fieldName);

src/validation/rules/SingleFieldSubscriptionsRule.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export function SingleFieldSubscriptionsRule(
4141
fragments[definition.name.value] = definition;
4242
}
4343
}
44-
const { fields } = collectFields(
44+
const { groupedFieldSet } = collectFields(
4545
schema,
4646
fragments,
4747
variableValues,
4848
subscriptionType,
4949
node,
5050
);
51-
if (fields.size > 1) {
52-
const fieldSelectionLists = [...fields.values()];
51+
if (groupedFieldSet.size > 1) {
52+
const fieldSelectionLists = [...groupedFieldSet.values()];
5353
const extraFieldSelectionLists = fieldSelectionLists.slice(1);
5454
const extraFieldSelections = extraFieldSelectionLists.flat();
5555
context.reportError(
@@ -61,7 +61,7 @@ export function SingleFieldSubscriptionsRule(
6161
),
6262
);
6363
}
64-
for (const fieldGroup of fields.values()) {
64+
for (const fieldGroup of groupedFieldSet.values()) {
6565
const fieldName = fieldGroup[0].name.value;
6666
if (fieldName.startsWith('__')) {
6767
context.reportError(

0 commit comments

Comments
 (0)