Skip to content

Commit a34a9c7

Browse files
committed
use groupedFieldSet as variable name
to match type
1 parent 37e5748 commit a34a9c7

3 files changed

Lines changed: 46 additions & 24 deletions

File tree

src/execution/collectFields.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ export function collectFields(
4141
variableValues: { [variable: string]: unknown },
4242
runtimeType: GraphQLObjectType,
4343
selectionSet: SelectionSetNode,
44-
): Map<string, FieldGroup> {
45-
const fields = new AccumulatorMap<string, FieldNode>();
44+
): GroupedFieldSet {
45+
const groupedFieldSet = new AccumulatorMap<string, FieldNode>();
4646
collectFieldsImpl(
4747
schema,
4848
fragments,
4949
variableValues,
5050
runtimeType,
5151
selectionSet,
52-
fields,
52+
groupedFieldSet,
5353
new Set(),
5454
);
55-
return fields;
55+
return groupedFieldSet;
5656
}
5757

5858
/**
@@ -71,8 +71,8 @@ export function collectSubfields(
7171
variableValues: { [variable: string]: unknown },
7272
returnType: GraphQLObjectType,
7373
fieldGroup: FieldGroup,
74-
): Map<string, FieldGroup> {
75-
const subFieldNodes = new AccumulatorMap<string, FieldNode>();
74+
): GroupedFieldSet {
75+
const subGroupedFieldSet = new AccumulatorMap<string, FieldNode>();
7676
const visitedFragmentNames = new Set<string>();
7777
for (const node of fieldGroup) {
7878
if (node.selectionSet) {
@@ -82,12 +82,12 @@ export function collectSubfields(
8282
variableValues,
8383
returnType,
8484
node.selectionSet,
85-
subFieldNodes,
85+
subGroupedFieldSet,
8686
visitedFragmentNames,
8787
);
8888
}
8989
}
90-
return subFieldNodes;
90+
return subGroupedFieldSet;
9191
}
9292

9393
// eslint-disable-next-line max-params
@@ -97,7 +97,7 @@ function collectFieldsImpl(
9797
variableValues: { [variable: string]: unknown },
9898
runtimeType: GraphQLObjectType,
9999
selectionSet: SelectionSetNode,
100-
fields: AccumulatorMap<string, FieldNode>,
100+
groupedFieldSet: AccumulatorMap<string, FieldNode>,
101101
visitedFragmentNames: Set<string>,
102102
): void {
103103
for (const selection of selectionSet.selections) {
@@ -106,7 +106,7 @@ function collectFieldsImpl(
106106
if (!shouldIncludeNode(variableValues, selection)) {
107107
continue;
108108
}
109-
fields.add(getFieldEntryKey(selection), selection);
109+
groupedFieldSet.add(getFieldEntryKey(selection), selection);
110110
break;
111111
}
112112
case Kind.INLINE_FRAGMENT: {
@@ -122,7 +122,7 @@ function collectFieldsImpl(
122122
variableValues,
123123
runtimeType,
124124
selection.selectionSet,
125-
fields,
125+
groupedFieldSet,
126126
visitedFragmentNames,
127127
);
128128
break;
@@ -149,7 +149,7 @@ function collectFieldsImpl(
149149
variableValues,
150150
runtimeType,
151151
fragment.selectionSet,
152-
fields,
152+
groupedFieldSet,
153153
visitedFragmentNames,
154154
);
155155
break;

src/execution/execute.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ function executeOperation(
397397
);
398398
}
399399

400-
const rootFields = collectFields(
400+
const groupedFieldSet = collectFields(
401401
schema,
402402
fragments,
403403
variableValues,
@@ -408,19 +408,31 @@ function executeOperation(
408408

409409
switch (operation.operation) {
410410
case OperationTypeNode.QUERY:
411-
return executeFields(exeContext, rootType, rootValue, path, rootFields);
411+
return executeFields(
412+
exeContext,
413+
rootType,
414+
rootValue,
415+
path,
416+
groupedFieldSet,
417+
);
412418
case OperationTypeNode.MUTATION:
413419
return executeFieldsSerially(
414420
exeContext,
415421
rootType,
416422
rootValue,
417423
path,
418-
rootFields,
424+
groupedFieldSet,
419425
);
420426
case OperationTypeNode.SUBSCRIPTION:
421427
// TODO: deprecate `subscribe` and move all logic here
422428
// Temporary solution until we finish merging execute and subscribe together
423-
return executeFields(exeContext, rootType, rootValue, path, rootFields);
429+
return executeFields(
430+
exeContext,
431+
rootType,
432+
rootValue,
433+
path,
434+
groupedFieldSet,
435+
);
424436
}
425437
}
426438

@@ -1153,9 +1165,19 @@ function collectAndExecuteSubfields(
11531165
result: unknown,
11541166
): PromiseOrValue<ObjMap<unknown>> {
11551167
// Collect sub-fields to execute to complete this value.
1156-
const subFieldNodes = collectSubfields(exeContext, returnType, fieldGroup);
1168+
const subGroupedFieldSet = collectSubfields(
1169+
exeContext,
1170+
returnType,
1171+
fieldGroup,
1172+
);
11571173

1158-
return executeFields(exeContext, returnType, result, path, subFieldNodes);
1174+
return executeFields(
1175+
exeContext,
1176+
returnType,
1177+
result,
1178+
path,
1179+
subGroupedFieldSet,
1180+
);
11591181
}
11601182

11611183
/**
@@ -1367,15 +1389,15 @@ function executeSubscription(
13671389
);
13681390
}
13691391

1370-
const rootFields = collectFields(
1392+
const groupedFieldSet = collectFields(
13711393
schema,
13721394
fragments,
13731395
variableValues,
13741396
rootType,
13751397
operation.selectionSet,
13761398
);
13771399

1378-
const firstRootField = rootFields.entries().next().value;
1400+
const firstRootField = groupedFieldSet.entries().next().value;
13791401
const [responseName, fieldGroup] = firstRootField;
13801402
const fieldName = fieldGroup[0].name.value;
13811403
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.selectionSet,
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)