Skip to content

Commit d89f6f9

Browse files
authored
refactor: extract ExecutionArgs types to separate file (#4770)
BREAKING CHANGE only for those doing deep exports (which we don't officially support, but....)
1 parent b1bc0ae commit d89f6f9

12 files changed

Lines changed: 151 additions & 137 deletions

File tree

src/execution/ExecutionArgs.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/** @category Execution */
2+
3+
import type { Maybe } from '../jsutils/Maybe.ts';
4+
import type { ObjMap } from '../jsutils/ObjMap.ts';
5+
6+
import type {
7+
DocumentNode,
8+
FragmentDefinitionNode,
9+
OperationDefinitionNode,
10+
SubscriptionOperationDefinitionNode,
11+
} from '../language/ast.ts';
12+
13+
import type {
14+
GraphQLFieldResolver,
15+
GraphQLTypeResolver,
16+
} from '../type/definition.ts';
17+
import type { GraphQLSchema } from '../type/schema.ts';
18+
19+
import type { FragmentDetails } from './collectFields.ts';
20+
import type { VariableValues } from './values.ts';
21+
22+
/** Arguments accepted by execute and executeSync. */
23+
export interface ExecutionArgs {
24+
/** The schema used for validation or execution. */
25+
schema: GraphQLSchema;
26+
/** The parsed GraphQL document to execute. */
27+
document: DocumentNode;
28+
/** Initial root value passed to the operation. */
29+
rootValue?: unknown;
30+
/** Application context value passed to every resolver. */
31+
contextValue?: unknown;
32+
/** Runtime variable values keyed by variable name. */
33+
variableValues?: Maybe<{ readonly [variable: string]: unknown }>;
34+
/** Name of the operation to execute when the document contains multiple operations. */
35+
operationName?: Maybe<string>;
36+
/** Resolver used when a field does not define its own resolver. */
37+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
38+
/** Resolver used when an abstract type does not define its own resolver. */
39+
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
40+
/** Resolver used for the root subscription field. */
41+
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
42+
/** Whether suggestion text should be omitted from request errors. */
43+
hideSuggestions?: Maybe<boolean>;
44+
/** AbortSignal used to cancel execution. */
45+
abortSignal?: Maybe<AbortSignal>;
46+
/** Whether incremental execution may begin eligible work early. */
47+
enableEarlyExecution?: Maybe<boolean>;
48+
/** Execution hooks invoked during this operation. */
49+
hooks?: Maybe<ExecutionHooks>;
50+
/** Additional execution options. */
51+
options?: {
52+
/**
53+
* Set the maximum number of errors allowed for coercing (defaults to 50).
54+
*
55+
* @internal
56+
*/
57+
maxCoercionErrors?: number;
58+
};
59+
}
60+
61+
/**
62+
* Data that must be available at all points during query execution.
63+
*
64+
* Namely, schema of the type system that is currently executing,
65+
* and the fragments defined in the query document
66+
*/
67+
export interface ValidatedExecutionArgs {
68+
/** Schema used for execution. */
69+
schema: GraphQLSchema;
70+
// TODO: consider deprecating/removing fragmentDefinitions if/when fragment
71+
// arguments are officially supported and/or the full fragment details are
72+
// exposed within GraphQLResolveInfo.
73+
/** Fragment definitions keyed by fragment name. */
74+
fragmentDefinitions: ObjMap<FragmentDefinitionNode>;
75+
/** Fragment details keyed by fragment name. */
76+
fragments: ObjMap<FragmentDetails>;
77+
/** Root value passed to the operation. */
78+
rootValue: unknown;
79+
/** Application context value passed to every resolver. */
80+
contextValue: unknown;
81+
/** Operation definition selected for execution. */
82+
operation: OperationDefinitionNode;
83+
/** Operation variable values with source metadata and coerced runtime values. */
84+
variableValues: VariableValues;
85+
/** Resolver used for fields without an explicit resolver. */
86+
fieldResolver: GraphQLFieldResolver<any, any>;
87+
/** Resolver used for abstract types without an explicit type resolver. */
88+
typeResolver: GraphQLTypeResolver<any, any>;
89+
/** Resolver used for subscription fields without an explicit subscribe resolver. */
90+
subscribeFieldResolver: GraphQLFieldResolver<any, any>;
91+
/** Whether suggestion text should be omitted from execution errors. */
92+
hideSuggestions: boolean;
93+
/** Whether execution should use error propagation. */
94+
errorPropagation: boolean;
95+
/** External signal that may abort execution. */
96+
externalAbortSignal: AbortSignal | undefined;
97+
/** Whether incremental execution may begin eligible work early. */
98+
enableEarlyExecution: boolean;
99+
/** Execution hooks supplied by the caller. */
100+
hooks: ExecutionHooks | undefined;
101+
}
102+
103+
/** Validated execution arguments for a subscription operation. */
104+
export interface ValidatedSubscriptionArgs extends ValidatedExecutionArgs {
105+
/** Subscription operation definition selected for execution. */
106+
operation: SubscriptionOperationDefinitionNode;
107+
}
108+
109+
/** Information passed to hooks after asynchronous execution work has finished. */
110+
export interface AsyncWorkFinishedInfo {
111+
/** Validated execution arguments for the operation that finished async work. */
112+
validatedExecutionArgs: ValidatedExecutionArgs;
113+
}
114+
115+
/** Optional hooks invoked during GraphQL execution. */
116+
export interface ExecutionHooks {
117+
/** Called after all tracked asynchronous execution work has settled. */
118+
asyncWorkFinished?: (info: AsyncWorkFinishedInfo) => void;
119+
}

src/execution/Executor.ts

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,17 @@ import type { GraphQLFormattedError } from '../error/GraphQLError.ts';
1919
import { GraphQLError } from '../error/GraphQLError.ts';
2020
import { locatedError } from '../error/locatedError.ts';
2121

22-
import type {
23-
FieldNode,
24-
FragmentDefinitionNode,
25-
OperationDefinitionNode,
26-
SubscriptionOperationDefinitionNode,
27-
} from '../language/ast.ts';
22+
import type { FieldNode } from '../language/ast.ts';
2823
import { OperationTypeNode } from '../language/ast.ts';
2924

3025
import type {
3126
GraphQLAbstractType,
32-
GraphQLFieldResolver,
3327
GraphQLLeafType,
3428
GraphQLList,
3529
GraphQLObjectType,
3630
GraphQLOutputType,
3731
GraphQLResolveInfo,
3832
GraphQLResolveInfoHelpers,
39-
GraphQLTypeResolver,
4033
} from '../type/definition.ts';
4134
import {
4235
isAbstractType,
@@ -53,7 +46,6 @@ import { withCancellation } from './cancellablePromise.ts';
5346
import type {
5447
DeferUsage,
5548
FieldDetailsList,
56-
FragmentDetails,
5749
GroupedFieldSet,
5850
} from './collectFields.ts';
5951
import {
@@ -63,12 +55,11 @@ import {
6355
import { collectIteratorPromises } from './collectIteratorPromises.ts';
6456
import type { SharedExecutionContext } from './createSharedExecutionContext.ts';
6557
import { createSharedExecutionContext } from './createSharedExecutionContext.ts';
58+
import type { ValidatedExecutionArgs } from './ExecutionArgs.ts';
6659
import type { StreamUsage } from './getStreamUsage.ts';
6760
import { getStreamUsage as _getStreamUsage } from './getStreamUsage.ts';
68-
import type { ExecutionHooks } from './hooks.ts';
6961
import { runAsyncWorkFinishedHook } from './hooks.ts';
7062
import { returnIteratorCatchingErrors } from './returnIteratorCatchingErrors.ts';
71-
import type { VariableValues } from './values.ts';
7263
import { getArgumentValues } from './values.ts';
7364

7465
/* eslint-disable max-params */
@@ -97,54 +88,6 @@ import { getArgumentValues } from './values.ts';
9788
* @internal
9889
*/
9990

100-
/**
101-
* Data that must be available at all points during query execution.
102-
*
103-
* Namely, schema of the type system that is currently executing,
104-
* and the fragments defined in the query document
105-
*/
106-
export interface ValidatedExecutionArgs {
107-
/** Schema used for execution. */
108-
schema: GraphQLSchema;
109-
// TODO: consider deprecating/removing fragmentDefinitions if/when fragment
110-
// arguments are officially supported and/or the full fragment details are
111-
// exposed within GraphQLResolveInfo.
112-
/** Fragment definitions keyed by fragment name. */
113-
fragmentDefinitions: ObjMap<FragmentDefinitionNode>;
114-
/** Fragment details keyed by fragment name. */
115-
fragments: ObjMap<FragmentDetails>;
116-
/** Root value passed to the operation. */
117-
rootValue: unknown;
118-
/** Application context value passed to every resolver. */
119-
contextValue: unknown;
120-
/** Operation definition selected for execution. */
121-
operation: OperationDefinitionNode;
122-
/** Operation variable values with source metadata and coerced runtime values. */
123-
variableValues: VariableValues;
124-
/** Resolver used for fields without an explicit resolver. */
125-
fieldResolver: GraphQLFieldResolver<any, any>;
126-
/** Resolver used for abstract types without an explicit type resolver. */
127-
typeResolver: GraphQLTypeResolver<any, any>;
128-
/** Resolver used for subscription fields without an explicit subscribe resolver. */
129-
subscribeFieldResolver: GraphQLFieldResolver<any, any>;
130-
/** Whether suggestion text should be omitted from execution errors. */
131-
hideSuggestions: boolean;
132-
/** Whether execution should use error propagation. */
133-
errorPropagation: boolean;
134-
/** External signal that may abort execution. */
135-
externalAbortSignal: AbortSignal | undefined;
136-
/** Whether incremental execution may begin eligible work early. */
137-
enableEarlyExecution: boolean;
138-
/** Execution hooks supplied by the caller. */
139-
hooks: ExecutionHooks | undefined;
140-
}
141-
142-
/** Validated execution arguments for a subscription operation. */
143-
export interface ValidatedSubscriptionArgs extends ValidatedExecutionArgs {
144-
/** Subscription operation definition selected for execution. */
145-
operation: SubscriptionOperationDefinitionNode;
146-
}
147-
14891
/**
14992
* A memoized collection of relevant subfields with regard to the return
15093
* type. Memoizing ensures the subfields are not repeatedly calculated, which

src/execution/__tests__/executor-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import {
3333
import { GraphQLSchema } from '../../type/schema.ts';
3434

3535
import type { FieldDetailsList } from '../collectFields.ts';
36-
import type { ExecutionArgs } from '../execute.ts';
3736
import {
3837
execute as executeThrowingOnIncremental,
3938
executeIgnoringIncremental,
4039
executeSync as executeSyncWrappingThrowingOnIncremental,
4140
experimentalExecuteIncrementally,
4241
validateExecutionArgs,
4342
} from '../execute.ts';
43+
import type { ExecutionArgs } from '../ExecutionArgs.ts';
4444
import type { ExecutionResult } from '../Executor.ts';
4545
import { collectSubfields, getStreamUsage } from '../Executor.ts';
4646
import { legacyExecuteIncrementally } from '../legacyIncremental/legacyExecuteIncrementally.ts';

src/execution/__tests__/hooks-test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import { GraphQLSchema } from '../../type/schema.ts';
2020
import { buildSchema } from '../../utilities/buildASTSchema.ts';
2121

2222
import type { SharedExecutionContext } from '../createSharedExecutionContext.ts';
23-
import type { ExecutionArgs } from '../execute.ts';
2423
import { execute, experimentalExecuteIncrementally } from '../execute.ts';
25-
import type { ExecutionResult, ValidatedExecutionArgs } from '../Executor.ts';
24+
import type {
25+
ExecutionArgs,
26+
ValidatedExecutionArgs,
27+
} from '../ExecutionArgs.ts';
28+
import type { ExecutionResult } from '../Executor.ts';
2629
import { runAsyncWorkFinishedHook } from '../hooks.ts';
2730

2831
const executeHookSchema = new GraphQLSchema({

src/execution/__tests__/subscribe-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import {
2222
} from '../../type/scalars.ts';
2323
import { GraphQLSchema } from '../../type/schema.ts';
2424

25-
import type { ExecutionArgs } from '../execute.ts';
2625
import {
2726
createSourceEventStream,
2827
executeSubscriptionEvent,
2928
mapSourceToResponseEvent,
3029
subscribe,
3130
validateSubscriptionArgs,
3231
} from '../execute.ts';
32+
import type { ExecutionArgs } from '../ExecutionArgs.ts';
3333
import type { ExecutionResult } from '../Executor.ts';
3434

3535
import { SimplePubSub } from './simplePubSub.ts';

src/execution/execute.ts

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { inspect } from '../jsutils/inspect.ts';
44
import { isAsyncIterable } from '../jsutils/isAsyncIterable.ts';
55
import { isObjectLike } from '../jsutils/isObjectLike.ts';
66
import { isPromise, isPromiseLike } from '../jsutils/isPromise.ts';
7-
import type { Maybe } from '../jsutils/Maybe.ts';
87
import type { ObjMap } from '../jsutils/ObjMap.ts';
98
import { addPath, pathToArray } from '../jsutils/Path.ts';
109
import type { PromiseOrValue } from '../jsutils/PromiseOrValue.ts';
@@ -14,7 +13,6 @@ import { GraphQLError } from '../error/GraphQLError.ts';
1413
import { locatedError } from '../error/locatedError.ts';
1514

1615
import type {
17-
DocumentNode,
1816
FieldNode,
1917
FragmentDefinitionNode,
2018
OperationDefinitionNode,
@@ -28,22 +26,21 @@ import type {
2826
GraphQLTypeResolver,
2927
} from '../type/index.ts';
3028
import { assertValidSchema } from '../type/index.ts';
31-
import type { GraphQLSchema } from '../type/schema.ts';
3229

3330
import { buildResolveInfo } from './buildResolveInfo.ts';
3431
import { cancellablePromise } from './cancellablePromise.ts';
3532
import type { FieldDetailsList, FragmentDetails } from './collectFields.ts';
3633
import { collectFields } from './collectFields.ts';
3734
import { createSharedExecutionContext } from './createSharedExecutionContext.ts';
3835
import type {
39-
ExecutionResult,
36+
ExecutionArgs,
4037
ValidatedExecutionArgs,
4138
ValidatedSubscriptionArgs,
42-
} from './Executor.ts';
39+
} from './ExecutionArgs.ts';
40+
import type { ExecutionResult } from './Executor.ts';
4341
import { Executor } from './Executor.ts';
4442
import { ExecutorThrowingOnIncremental } from './ExecutorThrowingOnIncremental.ts';
4543
import { getVariableSignature } from './getVariableSignature.ts';
46-
import type { ExecutionHooks } from './hooks.ts';
4744
import type { ExperimentalIncrementalExecutionResults } from './incremental/IncrementalExecutor.ts';
4845
import { IncrementalExecutor } from './incremental/IncrementalExecutor.ts';
4946
import { mapAsyncIterable } from './mapAsyncIterable.ts';
@@ -574,45 +571,6 @@ export function createSourceEventStream(
574571
}
575572
}
576573

577-
/** Arguments accepted by execute and executeSync. */
578-
export interface ExecutionArgs {
579-
/** The schema used for validation or execution. */
580-
schema: GraphQLSchema;
581-
/** The parsed GraphQL document to execute. */
582-
document: DocumentNode;
583-
/** Initial root value passed to the operation. */
584-
rootValue?: unknown;
585-
/** Application context value passed to every resolver. */
586-
contextValue?: unknown;
587-
/** Runtime variable values keyed by variable name. */
588-
variableValues?: Maybe<{ readonly [variable: string]: unknown }>;
589-
/** Name of the operation to execute when the document contains multiple operations. */
590-
operationName?: Maybe<string>;
591-
/** Resolver used when a field does not define its own resolver. */
592-
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
593-
/** Resolver used when an abstract type does not define its own resolver. */
594-
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
595-
/** Resolver used for the root subscription field. */
596-
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
597-
/** Whether suggestion text should be omitted from request errors. */
598-
hideSuggestions?: Maybe<boolean>;
599-
/** AbortSignal used to cancel execution. */
600-
abortSignal?: Maybe<AbortSignal>;
601-
/** Whether incremental execution may begin eligible work early. */
602-
enableEarlyExecution?: Maybe<boolean>;
603-
/** Execution hooks invoked during this operation. */
604-
hooks?: Maybe<ExecutionHooks>;
605-
/** Additional execution options. */
606-
options?: {
607-
/**
608-
* Set the maximum number of errors allowed for coercing (defaults to 50).
609-
*
610-
* @internal
611-
*/
612-
maxCoercionErrors?: number;
613-
};
614-
}
615-
616574
/**
617575
* Constructs a ExecutionContext object from the arguments passed to
618576
* execute, which we will pass throughout the other execution methods.

src/execution/getStreamUsage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OperationTypeNode } from '../language/ast.ts';
55
import { GraphQLStreamDirective } from '../type/directives.ts';
66

77
import type { FieldDetailsList } from './collectFields.ts';
8-
import type { ValidatedExecutionArgs } from './Executor.ts';
8+
import type { ValidatedExecutionArgs } from './ExecutionArgs.ts';
99
import { getDirectiveValues } from './values.ts';
1010

1111
/** @internal */

src/execution/hooks.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
/** @category Execution */
22

33
import type { SharedExecutionContext } from './createSharedExecutionContext.ts';
4-
import type { ValidatedExecutionArgs } from './Executor.ts';
5-
6-
/** Information passed to hooks after asynchronous execution work has finished. */
7-
export interface AsyncWorkFinishedInfo {
8-
/** Validated execution arguments for the operation that finished async work. */
9-
validatedExecutionArgs: ValidatedExecutionArgs;
10-
}
11-
12-
/** Optional hooks invoked during GraphQL execution. */
13-
export interface ExecutionHooks {
14-
/** Called after all tracked asynchronous execution work has settled. */
15-
asyncWorkFinished?: (info: AsyncWorkFinishedInfo) => void;
16-
}
4+
import type {
5+
AsyncWorkFinishedInfo,
6+
ValidatedExecutionArgs,
7+
} from './ExecutionArgs.ts';
178

189
function runHookSafely<TInfo>(hook: (info: TInfo) => void, info: TInfo): void {
1910
try {

0 commit comments

Comments
 (0)