Skip to content

Commit b0dffe5

Browse files
committed
use groupedFieldSet as variable name
to match type
1 parent 6493ca6 commit b0dffe5

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
@@ -358,7 +358,7 @@ function executeOperation(
358358
);
359359
}
360360

361-
const rootFields = collectFields(
361+
const groupedFieldSet = collectFields(
362362
schema,
363363
fragments,
364364
variableValues,
@@ -369,19 +369,31 @@ function executeOperation(
369369

370370
switch (operation.operation) {
371371
case OperationTypeNode.QUERY:
372-
return executeFields(exeContext, rootType, rootValue, path, rootFields);
372+
return executeFields(
373+
exeContext,
374+
rootType,
375+
rootValue,
376+
path,
377+
groupedFieldSet,
378+
);
373379
case OperationTypeNode.MUTATION:
374380
return executeFieldsSerially(
375381
exeContext,
376382
rootType,
377383
rootValue,
378384
path,
379-
rootFields,
385+
groupedFieldSet,
380386
);
381387
case OperationTypeNode.SUBSCRIPTION:
382388
// TODO: deprecate `subscribe` and move all logic here
383389
// Temporary solution until we finish merging execute and subscribe together
384-
return executeFields(exeContext, rootType, rootValue, path, rootFields);
390+
return executeFields(
391+
exeContext,
392+
rootType,
393+
rootValue,
394+
path,
395+
groupedFieldSet,
396+
);
385397
}
386398
}
387399

@@ -1113,9 +1125,19 @@ function collectAndExecuteSubfields(
11131125
result: unknown,
11141126
): PromiseOrValue<ObjMap<unknown>> {
11151127
// Collect sub-fields to execute to complete this value.
1116-
const subFieldNodes = collectSubfields(exeContext, returnType, fieldGroup);
1128+
const subGroupedFieldSet = collectSubfields(
1129+
exeContext,
1130+
returnType,
1131+
fieldGroup,
1132+
);
11171133

1118-
return executeFields(exeContext, returnType, result, path, subFieldNodes);
1134+
return executeFields(
1135+
exeContext,
1136+
returnType,
1137+
result,
1138+
path,
1139+
subGroupedFieldSet,
1140+
);
11191141
}
11201142

11211143
/**
@@ -1327,15 +1349,15 @@ function executeSubscription(
13271349
);
13281350
}
13291351

1330-
const rootFields = collectFields(
1352+
const groupedFieldSet = collectFields(
13311353
schema,
13321354
fragments,
13331355
variableValues,
13341356
rootType,
13351357
operation.selectionSet,
13361358
);
13371359

1338-
const firstRootField = rootFields.entries().next().value;
1360+
const firstRootField = groupedFieldSet.entries().next().value;
13391361
const [responseName, fieldGroup] = firstRootField;
13401362
const fieldName = fieldGroup[0].name.value;
13411363
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)