Skip to content

Commit b1dceba

Browse files
yaacovCRIvanGoncharov
authored andcommitted
introduce FieldGroup type
1 parent ddd6a01 commit b1dceba

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/execution/collectFields.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ import { typeFromAST } from '../utilities/typeFromAST.js';
2626

2727
import { getDirectiveValues } from './values.js';
2828

29+
export type FieldGroup = ReadonlyArray<FieldNode>;
30+
2931
export interface PatchFields {
3032
label: string | undefined;
31-
fields: Map<string, ReadonlyArray<FieldNode>>;
33+
fields: Map<string, FieldGroup>;
3234
}
3335

3436
export interface FieldsAndPatches {
35-
fields: Map<string, ReadonlyArray<FieldNode>>;
37+
fields: Map<string, FieldGroup>;
3638
patches: Array<PatchFields>;
3739
}
3840

@@ -85,7 +87,7 @@ export function collectSubfields(
8587
variableValues: { [variable: string]: unknown },
8688
operation: OperationDefinitionNode,
8789
returnType: GraphQLObjectType,
88-
fieldNodes: ReadonlyArray<FieldNode>,
90+
fieldNodes: FieldGroup,
8991
): FieldsAndPatches {
9092
const subFieldNodes = new AccumulatorMap<string, FieldNode>();
9193
const visitedFragmentNames = new Set<string>();

src/execution/execute.ts

Lines changed: 21 additions & 21 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';
@@ -48,6 +47,7 @@ import { GraphQLStreamDirective } from '../type/directives.js';
4847
import type { GraphQLSchema } from '../type/schema.js';
4948
import { assertValidSchema } from '../type/validate.js';
5049

50+
import type { FieldGroup } from './collectFields.js';
5151
import {
5252
collectFields,
5353
collectSubfields as _collectSubfields,
@@ -72,7 +72,7 @@ const collectSubfields = memoize3(
7272
(
7373
exeContext: ExecutionContext,
7474
returnType: GraphQLObjectType,
75-
fieldNodes: ReadonlyArray<FieldNode>,
75+
fieldNodes: FieldGroup,
7676
) =>
7777
_collectSubfields(
7878
exeContext.schema,
@@ -589,7 +589,7 @@ function executeFieldsSerially(
589589
parentType: GraphQLObjectType,
590590
sourceValue: unknown,
591591
path: Path | undefined,
592-
fields: Map<string, ReadonlyArray<FieldNode>>,
592+
fields: Map<string, FieldGroup>,
593593
): PromiseOrValue<ObjMap<unknown>> {
594594
return promiseReduce(
595595
fields,
@@ -627,7 +627,7 @@ function executeFields(
627627
parentType: GraphQLObjectType,
628628
sourceValue: unknown,
629629
path: Path | undefined,
630-
fields: Map<string, ReadonlyArray<FieldNode>>,
630+
fields: Map<string, FieldGroup>,
631631
asyncPayloadRecord?: AsyncPayloadRecord,
632632
): PromiseOrValue<ObjMap<unknown>> {
633633
const results = Object.create(null);
@@ -683,7 +683,7 @@ function executeField(
683683
exeContext: ExecutionContext,
684684
parentType: GraphQLObjectType,
685685
source: unknown,
686-
fieldNodes: ReadonlyArray<FieldNode>,
686+
fieldNodes: FieldGroup,
687687
path: Path,
688688
asyncPayloadRecord?: AsyncPayloadRecord,
689689
): PromiseOrValue<unknown> {
@@ -771,7 +771,7 @@ function executeField(
771771
export function buildResolveInfo(
772772
exeContext: ExecutionContext,
773773
fieldDef: GraphQLField<unknown, unknown>,
774-
fieldNodes: ReadonlyArray<FieldNode>,
774+
fieldNodes: FieldGroup,
775775
parentType: GraphQLObjectType,
776776
path: Path,
777777
): GraphQLResolveInfo {
@@ -832,7 +832,7 @@ function handleFieldError(
832832
function completeValue(
833833
exeContext: ExecutionContext,
834834
returnType: GraphQLOutputType,
835-
fieldNodes: ReadonlyArray<FieldNode>,
835+
fieldNodes: FieldGroup,
836836
info: GraphQLResolveInfo,
837837
path: Path,
838838
result: unknown,
@@ -924,7 +924,7 @@ function completeValue(
924924
async function completePromisedValue(
925925
exeContext: ExecutionContext,
926926
returnType: GraphQLOutputType,
927-
fieldNodes: ReadonlyArray<FieldNode>,
927+
fieldNodes: FieldGroup,
928928
info: GraphQLResolveInfo,
929929
path: Path,
930930
result: Promise<unknown>,
@@ -961,7 +961,7 @@ async function completePromisedValue(
961961
*/
962962
function getStreamValues(
963963
exeContext: ExecutionContext,
964-
fieldNodes: ReadonlyArray<FieldNode>,
964+
fieldNodes: FieldGroup,
965965
path: Path,
966966
):
967967
| undefined
@@ -1018,7 +1018,7 @@ function getStreamValues(
10181018
async function completeAsyncIteratorValue(
10191019
exeContext: ExecutionContext,
10201020
itemType: GraphQLOutputType,
1021-
fieldNodes: ReadonlyArray<FieldNode>,
1021+
fieldNodes: FieldGroup,
10221022
info: GraphQLResolveInfo,
10231023
path: Path,
10241024
iterator: AsyncIterator<unknown>,
@@ -1092,7 +1092,7 @@ async function completeAsyncIteratorValue(
10921092
function completeListValue(
10931093
exeContext: ExecutionContext,
10941094
returnType: GraphQLList<GraphQLOutputType>,
1095-
fieldNodes: ReadonlyArray<FieldNode>,
1095+
fieldNodes: FieldGroup,
10961096
info: GraphQLResolveInfo,
10971097
path: Path,
10981098
result: unknown,
@@ -1187,7 +1187,7 @@ function completeListItemValue(
11871187
errors: Array<GraphQLError>,
11881188
exeContext: ExecutionContext,
11891189
itemType: GraphQLOutputType,
1190-
fieldNodes: ReadonlyArray<FieldNode>,
1190+
fieldNodes: FieldGroup,
11911191
info: GraphQLResolveInfo,
11921192
itemPath: Path,
11931193
asyncPayloadRecord?: AsyncPayloadRecord,
@@ -1274,7 +1274,7 @@ function completeLeafValue(
12741274
function completeAbstractValue(
12751275
exeContext: ExecutionContext,
12761276
returnType: GraphQLAbstractType,
1277-
fieldNodes: ReadonlyArray<FieldNode>,
1277+
fieldNodes: FieldGroup,
12781278
info: GraphQLResolveInfo,
12791279
path: Path,
12801280
result: unknown,
@@ -1327,7 +1327,7 @@ function ensureValidRuntimeType(
13271327
runtimeTypeName: unknown,
13281328
exeContext: ExecutionContext,
13291329
returnType: GraphQLAbstractType,
1330-
fieldNodes: ReadonlyArray<FieldNode>,
1330+
fieldNodes: FieldGroup,
13311331
info: GraphQLResolveInfo,
13321332
result: unknown,
13331333
): GraphQLObjectType {
@@ -1384,7 +1384,7 @@ function ensureValidRuntimeType(
13841384
function completeObjectValue(
13851385
exeContext: ExecutionContext,
13861386
returnType: GraphQLObjectType,
1387-
fieldNodes: ReadonlyArray<FieldNode>,
1387+
fieldNodes: FieldGroup,
13881388
info: GraphQLResolveInfo,
13891389
path: Path,
13901390
result: unknown,
@@ -1430,7 +1430,7 @@ function completeObjectValue(
14301430
function invalidReturnTypeError(
14311431
returnType: GraphQLObjectType,
14321432
result: unknown,
1433-
fieldNodes: ReadonlyArray<FieldNode>,
1433+
fieldNodes: FieldGroup,
14341434
): GraphQLError {
14351435
return new GraphQLError(
14361436
`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`,
@@ -1441,7 +1441,7 @@ function invalidReturnTypeError(
14411441
function collectAndExecuteSubfields(
14421442
exeContext: ExecutionContext,
14431443
returnType: GraphQLObjectType,
1444-
fieldNodes: ReadonlyArray<FieldNode>,
1444+
fieldNodes: FieldGroup,
14451445
path: Path,
14461446
result: unknown,
14471447
asyncPayloadRecord?: AsyncPayloadRecord,
@@ -1770,7 +1770,7 @@ function executeDeferredFragment(
17701770
exeContext: ExecutionContext,
17711771
parentType: GraphQLObjectType,
17721772
sourceValue: unknown,
1773-
fields: Map<string, ReadonlyArray<FieldNode>>,
1773+
fields: Map<string, FieldGroup>,
17741774
label?: string,
17751775
path?: Path,
17761776
parentContext?: AsyncPayloadRecord,
@@ -1810,7 +1810,7 @@ function executeStreamField(
18101810
itemPath: Path,
18111811
item: PromiseOrValue<unknown>,
18121812
exeContext: ExecutionContext,
1813-
fieldNodes: ReadonlyArray<FieldNode>,
1813+
fieldNodes: FieldGroup,
18141814
info: GraphQLResolveInfo,
18151815
itemType: GraphQLOutputType,
18161816
label?: string,
@@ -1904,7 +1904,7 @@ function executeStreamField(
19041904
async function executeStreamIteratorItem(
19051905
iterator: AsyncIterator<unknown>,
19061906
exeContext: ExecutionContext,
1907-
fieldNodes: ReadonlyArray<FieldNode>,
1907+
fieldNodes: FieldGroup,
19081908
info: GraphQLResolveInfo,
19091909
itemType: GraphQLOutputType,
19101910
asyncPayloadRecord: StreamRecord,
@@ -1961,7 +1961,7 @@ async function executeStreamIterator(
19611961
initialIndex: number,
19621962
iterator: AsyncIterator<unknown>,
19631963
exeContext: ExecutionContext,
1964-
fieldNodes: ReadonlyArray<FieldNode>,
1964+
fieldNodes: FieldGroup,
19651965
info: GraphQLResolveInfo,
19661966
itemType: GraphQLOutputType,
19671967
path: Path,

0 commit comments

Comments
 (0)