@@ -22,6 +22,7 @@ import type {
22
22
OperationDefinitionNode ,
23
23
FieldNode ,
24
24
FragmentDefinitionNode ,
25
+ ASTNode ,
25
26
} from '../language/ast' ;
26
27
import { Kind } from '../language/kinds' ;
27
28
@@ -504,15 +505,13 @@ function executeField(
504
505
if ( isPromise ( completed ) ) {
505
506
// Note: we don't rely on a `catch` method, but we do expect "thenable"
506
507
// to take a second callback for the error case.
507
- return completed . then ( undefined , ( rawError ) => {
508
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
509
- return handleFieldError ( error , returnType , exeContext ) ;
510
- } ) ;
508
+ return completed . then ( undefined , ( rawError ) =>
509
+ handleRawError ( exeContext , returnType , rawError , fieldNodes , path ) ,
510
+ ) ;
511
511
}
512
512
return completed ;
513
513
} catch ( rawError ) {
514
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
515
- return handleFieldError ( error , returnType , exeContext ) ;
514
+ return handleRawError ( exeContext , returnType , rawError , fieldNodes , path ) ;
516
515
}
517
516
}
518
517
@@ -542,11 +541,15 @@ export function buildResolveInfo(
542
541
} ;
543
542
}
544
543
545
- function handleFieldError (
546
- error : GraphQLError ,
547
- returnType : GraphQLOutputType ,
544
+ function handleRawError (
548
545
exeContext : ExecutionContext ,
546
+ returnType : GraphQLOutputType ,
547
+ rawError : unknown ,
548
+ fieldNodes : ReadonlyArray < ASTNode > ,
549
+ path ?: Maybe < Readonly < Path > > ,
549
550
) : null {
551
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
552
+
550
553
// If the field type is non-nullable, then it is resolved without any
551
554
// protection from errors, however it still properly locates the error.
552
555
if ( isNonNullType ( returnType ) ) {
@@ -722,19 +725,19 @@ function completeListValue(
722
725
containsPromise = true ;
723
726
// Note: we don't rely on a `catch` method, but we do expect "thenable"
724
727
// to take a second callback for the error case.
725
- return completedItem . then ( undefined , ( rawError ) => {
726
- const error = locatedError (
727
- rawError ,
728
- fieldNodes ,
729
- pathToArray ( itemPath ) ,
730
- ) ;
731
- return handleFieldError ( error , itemType , exeContext ) ;
732
- } ) ;
728
+ return completedItem . then ( undefined , ( rawError ) =>
729
+ handleRawError ( exeContext , itemType , rawError , fieldNodes , itemPath ) ,
730
+ ) ;
733
731
}
734
732
return completedItem ;
735
733
} catch ( rawError ) {
736
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
737
- return handleFieldError ( error , itemType , exeContext ) ;
734
+ return handleRawError (
735
+ exeContext ,
736
+ itemType ,
737
+ rawError ,
738
+ fieldNodes ,
739
+ itemPath ,
740
+ ) ;
738
741
}
739
742
} ) ;
740
743
0 commit comments