|
| 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 | +} |
0 commit comments