@@ -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
@@ -525,15 +526,13 @@ function executeField(
525
526
if ( isPromise ( completed ) ) {
526
527
// Note: we don't rely on a `catch` method, but we do expect "thenable"
527
528
// to take a second callback for the error case.
528
- return completed . then ( undefined , ( rawError ) => {
529
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
530
- return handleFieldError ( error , returnType , exeContext ) ;
531
- } ) ;
529
+ return completed . then ( undefined , ( rawError ) =>
530
+ handleRawError ( exeContext , returnType , rawError , fieldNodes , path ) ,
531
+ ) ;
532
532
}
533
533
return completed ;
534
534
} catch ( rawError ) {
535
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
536
- return handleFieldError ( error , returnType , exeContext ) ;
535
+ return handleRawError ( exeContext , returnType , rawError , fieldNodes , path ) ;
537
536
}
538
537
}
539
538
@@ -563,11 +562,15 @@ export function buildResolveInfo(
563
562
} ;
564
563
}
565
564
566
- function handleFieldError (
567
- error : GraphQLError ,
568
- returnType : GraphQLOutputType ,
565
+ function handleRawError (
569
566
exeContext : ExecutionContext ,
567
+ returnType : GraphQLOutputType ,
568
+ rawError : unknown ,
569
+ fieldNodes : ReadonlyArray < ASTNode > ,
570
+ path ?: Maybe < Readonly < Path > > ,
570
571
) : null {
572
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
573
+
571
574
// If the field type is non-nullable, then it is resolved without any
572
575
// protection from errors, however it still properly locates the error.
573
576
if ( isNonNullType ( returnType ) ) {
@@ -743,19 +746,19 @@ function completeListValue(
743
746
containsPromise = true ;
744
747
// Note: we don't rely on a `catch` method, but we do expect "thenable"
745
748
// to take a second callback for the error case.
746
- return completedItem . then ( undefined , ( rawError ) => {
747
- const error = locatedError (
748
- rawError ,
749
- fieldNodes ,
750
- pathToArray ( itemPath ) ,
751
- ) ;
752
- return handleFieldError ( error , itemType , exeContext ) ;
753
- } ) ;
749
+ return completedItem . then ( undefined , ( rawError ) =>
750
+ handleRawError ( exeContext , itemType , rawError , fieldNodes , itemPath ) ,
751
+ ) ;
754
752
}
755
753
return completedItem ;
756
754
} catch ( rawError ) {
757
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
758
- return handleFieldError ( error , itemType , exeContext ) ;
755
+ return handleRawError (
756
+ exeContext ,
757
+ itemType ,
758
+ rawError ,
759
+ fieldNodes ,
760
+ itemPath ,
761
+ ) ;
759
762
}
760
763
} ) ;
761
764
0 commit comments