@@ -102,9 +102,18 @@ export interface ExecutionContext {
102
102
variableValues : { [ variable : string ] : unknown } ;
103
103
fieldResolver : GraphQLFieldResolver < any , any > ;
104
104
typeResolver : GraphQLTypeResolver < any , any > ;
105
+ fieldExecutor : GraphQLFieldExecutor ;
105
106
errors : Array < GraphQLError > ;
106
107
}
107
108
109
+ export type GraphQLFieldExecutor = (
110
+ exeContext : ExecutionContext ,
111
+ parentType : GraphQLObjectType ,
112
+ source : unknown ,
113
+ fieldNodes : ReadonlyArray < FieldNode > ,
114
+ path : Path ,
115
+ ) => PromiseOrValue < unknown > ;
116
+
108
117
/**
109
118
* The result of GraphQL execution.
110
119
*
@@ -139,6 +148,7 @@ export interface ExecutionArgs {
139
148
operationName ?: Maybe < string > ;
140
149
fieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ;
141
150
typeResolver ?: Maybe < GraphQLTypeResolver < any , any > > ;
151
+ fieldExecutor ?: Maybe < GraphQLFieldExecutor > ;
142
152
}
143
153
144
154
/**
@@ -161,6 +171,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
161
171
operationName,
162
172
fieldResolver,
163
173
typeResolver,
174
+ fieldExecutor,
164
175
} = args ;
165
176
166
177
// If arguments are missing or incorrect, throw an error.
@@ -177,6 +188,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
177
188
operationName ,
178
189
fieldResolver ,
179
190
typeResolver ,
191
+ fieldExecutor ,
180
192
) ;
181
193
182
194
// Return early errors if execution context failed.
@@ -267,6 +279,7 @@ export function buildExecutionContext(
267
279
operationName : Maybe < string > ,
268
280
fieldResolver : Maybe < GraphQLFieldResolver < unknown , unknown > > ,
269
281
typeResolver ?: Maybe < GraphQLTypeResolver < unknown , unknown > > ,
282
+ fieldExecutor ?: Maybe < GraphQLFieldExecutor > ,
270
283
) : ReadonlyArray < GraphQLError > | ExecutionContext {
271
284
let operation : OperationDefinitionNode | undefined ;
272
285
const fragments : ObjMap < FragmentDefinitionNode > = Object . create ( null ) ;
@@ -322,6 +335,7 @@ export function buildExecutionContext(
322
335
variableValues : coercedVariableValues . coerced ,
323
336
fieldResolver : fieldResolver ?? defaultFieldResolver ,
324
337
typeResolver : typeResolver ?? defaultTypeResolver ,
338
+ fieldExecutor : fieldExecutor ?? defaultFieldExecutor ,
325
339
errors : [ ] ,
326
340
} ;
327
341
}
@@ -381,7 +395,7 @@ function executeFieldsSerially(
381
395
fields . entries ( ) ,
382
396
( results , [ responseName , fieldNodes ] ) => {
383
397
const fieldPath = addPath ( path , responseName , parentType . name ) ;
384
- const result = executeField (
398
+ const result = exeContext . fieldExecutor (
385
399
exeContext ,
386
400
parentType ,
387
401
sourceValue ,
@@ -420,7 +434,7 @@ function executeFields(
420
434
421
435
for ( const [ responseName , fieldNodes ] of fields . entries ( ) ) {
422
436
const fieldPath = addPath ( path , responseName , parentType . name ) ;
423
- const result = executeField (
437
+ const result = exeContext . fieldExecutor (
424
438
exeContext ,
425
439
parentType ,
426
440
sourceValue ,
@@ -588,13 +602,13 @@ function getFieldEntryKey(node: FieldNode): string {
588
602
* calling its resolve function, then calls completeValue to complete promises,
589
603
* serialize scalars, or execute the sub-selection-set for objects.
590
604
*/
591
- function executeField (
592
- exeContext : ExecutionContext ,
593
- parentType : GraphQLObjectType ,
594
- source : unknown ,
595
- fieldNodes : ReadonlyArray < FieldNode > ,
596
- path : Path ,
597
- ) : PromiseOrValue < unknown > {
605
+ export const defaultFieldExecutor : GraphQLFieldExecutor = (
606
+ exeContext ,
607
+ parentType ,
608
+ source ,
609
+ fieldNodes ,
610
+ path ,
611
+ ) = > {
598
612
const fieldDef = getFieldDef ( exeContext . schema , parentType , fieldNodes [ 0 ] ) ;
599
613
if ( ! fieldDef ) {
600
614
return ;
@@ -658,7 +672,7 @@ function executeField(
658
672
const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
659
673
return handleFieldError ( error , returnType , exeContext ) ;
660
674
}
661
- }
675
+ } ;
662
676
663
677
/**
664
678
* @internal
0 commit comments