Skip to content

Commit 8c5db67

Browse files
committed
introduce FieldGroup type
1 parent 51ee5fb commit 8c5db67

2 files changed

Lines changed: 21 additions & 19 deletions

File tree

src/execution/collectFields.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { typeFromAST } from '../utilities/typeFromAST.js';
2222

2323
import { getDirectiveValues } from './values.js';
2424

25+
export type FieldGroup = ReadonlyArray<FieldNode>;
26+
2527
/**
2628
* Given a selectionSet, collects all of the fields and returns them.
2729
*
@@ -37,7 +39,7 @@ export function collectFields(
3739
variableValues: { [variable: string]: unknown },
3840
runtimeType: GraphQLObjectType,
3941
selectionSet: SelectionSetNode,
40-
): Map<string, ReadonlyArray<FieldNode>> {
42+
): Map<string, FieldGroup> {
4143
const fields = new AccumulatorMap<string, FieldNode>();
4244
collectFieldsImpl(
4345
schema,
@@ -66,8 +68,8 @@ export function collectSubfields(
6668
fragments: ObjMap<FragmentDefinitionNode>,
6769
variableValues: { [variable: string]: unknown },
6870
returnType: GraphQLObjectType,
69-
fieldNodes: ReadonlyArray<FieldNode>,
70-
): Map<string, ReadonlyArray<FieldNode>> {
71+
fieldNodes: FieldGroup,
72+
): Map<string, FieldGroup> {
7173
const subFieldNodes = new AccumulatorMap<string, FieldNode>();
7274
const visitedFragmentNames = new Set<string>();
7375
for (const node of fieldNodes) {

src/execution/execute.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { locatedError } from '../error/locatedError.js';
1919

2020
import type {
2121
DocumentNode,
22-
FieldNode,
2322
FragmentDefinitionNode,
2423
OperationDefinitionNode,
2524
} from '../language/ast.js';
@@ -47,6 +46,7 @@ import {
4746
import type { GraphQLSchema } from '../type/schema.js';
4847
import { assertValidSchema } from '../type/validate.js';
4948

49+
import type { FieldGroup } from './collectFields.js';
5050
import {
5151
collectFields,
5252
collectSubfields as _collectSubfields,
@@ -67,7 +67,7 @@ const collectSubfields = memoize3(
6767
(
6868
exeContext: ExecutionContext,
6969
returnType: GraphQLObjectType,
70-
fieldNodes: ReadonlyArray<FieldNode>,
70+
fieldNodes: FieldGroup,
7171
) =>
7272
_collectSubfields(
7373
exeContext.schema,
@@ -433,7 +433,7 @@ function executeFieldsSerially(
433433
parentType: GraphQLObjectType,
434434
sourceValue: unknown,
435435
path: Path | undefined,
436-
fields: Map<string, ReadonlyArray<FieldNode>>,
436+
fields: Map<string, FieldGroup>,
437437
): PromiseOrValue<ObjMap<unknown>> {
438438
return promiseReduce(
439439
fields,
@@ -471,7 +471,7 @@ function executeFields(
471471
parentType: GraphQLObjectType,
472472
sourceValue: unknown,
473473
path: Path | undefined,
474-
fields: Map<string, ReadonlyArray<FieldNode>>,
474+
fields: Map<string, FieldGroup>,
475475
): PromiseOrValue<ObjMap<unknown>> {
476476
const results = Object.create(null);
477477
let containsPromise = false;
@@ -525,7 +525,7 @@ function executeField(
525525
exeContext: ExecutionContext,
526526
parentType: GraphQLObjectType,
527527
source: unknown,
528-
fieldNodes: ReadonlyArray<FieldNode>,
528+
fieldNodes: FieldGroup,
529529
path: Path,
530530
): PromiseOrValue<unknown> {
531531
const fieldName = fieldNodes[0].name.value;
@@ -605,7 +605,7 @@ function executeField(
605605
export function buildResolveInfo(
606606
exeContext: ExecutionContext,
607607
fieldDef: GraphQLField<unknown, unknown>,
608-
fieldNodes: ReadonlyArray<FieldNode>,
608+
fieldNodes: FieldGroup,
609609
parentType: GraphQLObjectType,
610610
path: Path,
611611
): GraphQLResolveInfo {
@@ -667,7 +667,7 @@ function handleFieldError(
667667
function completeValue(
668668
exeContext: ExecutionContext,
669669
returnType: GraphQLOutputType,
670-
fieldNodes: ReadonlyArray<FieldNode>,
670+
fieldNodes: FieldGroup,
671671
info: GraphQLResolveInfo,
672672
path: Path,
673673
result: unknown,
@@ -753,7 +753,7 @@ function completeValue(
753753
async function completePromisedValue(
754754
exeContext: ExecutionContext,
755755
returnType: GraphQLOutputType,
756-
fieldNodes: ReadonlyArray<FieldNode>,
756+
fieldNodes: FieldGroup,
757757
info: GraphQLResolveInfo,
758758
path: Path,
759759
result: Promise<unknown>,
@@ -785,7 +785,7 @@ async function completePromisedValue(
785785
async function completeAsyncIteratorValue(
786786
exeContext: ExecutionContext,
787787
itemType: GraphQLOutputType,
788-
fieldNodes: ReadonlyArray<FieldNode>,
788+
fieldNodes: FieldGroup,
789789
info: GraphQLResolveInfo,
790790
path: Path,
791791
iterator: AsyncIterator<unknown>,
@@ -835,7 +835,7 @@ async function completeAsyncIteratorValue(
835835
function completeListValue(
836836
exeContext: ExecutionContext,
837837
returnType: GraphQLList<GraphQLOutputType>,
838-
fieldNodes: ReadonlyArray<FieldNode>,
838+
fieldNodes: FieldGroup,
839839
info: GraphQLResolveInfo,
840840
path: Path,
841841
result: unknown,
@@ -901,7 +901,7 @@ function completeListItemValue(
901901
completedResults: Array<unknown>,
902902
exeContext: ExecutionContext,
903903
itemType: GraphQLOutputType,
904-
fieldNodes: ReadonlyArray<FieldNode>,
904+
fieldNodes: FieldGroup,
905905
info: GraphQLResolveInfo,
906906
itemPath: Path,
907907
): boolean {
@@ -987,7 +987,7 @@ function completeLeafValue(
987987
function completeAbstractValue(
988988
exeContext: ExecutionContext,
989989
returnType: GraphQLAbstractType,
990-
fieldNodes: ReadonlyArray<FieldNode>,
990+
fieldNodes: FieldGroup,
991991
info: GraphQLResolveInfo,
992992
path: Path,
993993
result: unknown,
@@ -1037,7 +1037,7 @@ function ensureValidRuntimeType(
10371037
runtimeTypeName: unknown,
10381038
exeContext: ExecutionContext,
10391039
returnType: GraphQLAbstractType,
1040-
fieldNodes: ReadonlyArray<FieldNode>,
1040+
fieldNodes: FieldGroup,
10411041
info: GraphQLResolveInfo,
10421042
result: unknown,
10431043
): GraphQLObjectType {
@@ -1094,7 +1094,7 @@ function ensureValidRuntimeType(
10941094
function completeObjectValue(
10951095
exeContext: ExecutionContext,
10961096
returnType: GraphQLObjectType,
1097-
fieldNodes: ReadonlyArray<FieldNode>,
1097+
fieldNodes: FieldGroup,
10981098
info: GraphQLResolveInfo,
10991099
path: Path,
11001100
result: unknown,
@@ -1137,7 +1137,7 @@ function completeObjectValue(
11371137
function invalidReturnTypeError(
11381138
returnType: GraphQLObjectType,
11391139
result: unknown,
1140-
fieldNodes: ReadonlyArray<FieldNode>,
1140+
fieldNodes: FieldGroup,
11411141
): GraphQLError {
11421142
return new GraphQLError(
11431143
`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`,
@@ -1148,7 +1148,7 @@ function invalidReturnTypeError(
11481148
function collectAndExecuteSubfields(
11491149
exeContext: ExecutionContext,
11501150
returnType: GraphQLObjectType,
1151-
fieldNodes: ReadonlyArray<FieldNode>,
1151+
fieldNodes: FieldGroup,
11521152
path: Path,
11531153
result: unknown,
11541154
): PromiseOrValue<ObjMap<unknown>> {

0 commit comments

Comments
 (0)