@@ -489,6 +489,7 @@ function executeField(
489489 fieldNodes : ReadonlyArray < FieldNode > ,
490490 path : Path ,
491491) : PromiseOrValue < unknown > {
492+ const errors = exeContext . errors ;
492493 const fieldName = fieldNodes [ 0 ] . name . value ;
493494 const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
494495 if ( ! fieldDef ) {
@@ -545,13 +546,13 @@ function executeField(
545546 // to take a second callback for the error case.
546547 return completed . then ( undefined , ( rawError ) => {
547548 const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
548- return handleFieldError ( error , returnType , exeContext ) ;
549+ return handleFieldError ( error , returnType , errors ) ;
549550 } ) ;
550551 }
551552 return completed ;
552553 } catch ( rawError ) {
553554 const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
554- return handleFieldError ( error , returnType , exeContext ) ;
555+ return handleFieldError ( error , returnType , errors ) ;
555556 }
556557}
557558
@@ -585,7 +586,7 @@ export function buildResolveInfo(
585586function handleFieldError (
586587 error : GraphQLError ,
587588 returnType : GraphQLOutputType ,
588- exeContext : ExecutionContext ,
589+ errors : Array < GraphQLError > ,
589590) : null {
590591 // If the field type is non-nullable, then it is resolved without any
591592 // protection from errors, however it still properly locates the error.
@@ -595,7 +596,7 @@ function handleFieldError(
595596
596597 // Otherwise, error protection is applied, logging the error and resolving
597598 // a null value for this field if one is encountered.
598- exeContext . errors . push ( error ) ;
599+ errors . push ( error ) ;
599600 return null ;
600601}
601602
@@ -718,6 +719,7 @@ async function completeAsyncIteratorValue(
718719 path : Path ,
719720 iterator : AsyncIterator < unknown > ,
720721) : Promise < ReadonlyArray < unknown > > {
722+ const errors = exeContext . errors ;
721723 let containsPromise = false ;
722724 const completedResults = [ ] ;
723725 let index = 0 ;
@@ -752,12 +754,12 @@ async function completeAsyncIteratorValue(
752754 fieldNodes ,
753755 pathToArray ( fieldPath ) ,
754756 ) ;
755- handleFieldError ( error , itemType , exeContext ) ;
757+ handleFieldError ( error , itemType , errors ) ;
756758 }
757759 } catch ( rawError ) {
758760 completedResults . push ( null ) ;
759761 const error = locatedError ( rawError , fieldNodes , pathToArray ( fieldPath ) ) ;
760- handleFieldError ( error , itemType , exeContext ) ;
762+ handleFieldError ( error , itemType , errors ) ;
761763 break ;
762764 }
763765 index += 1 ;
@@ -778,6 +780,7 @@ function completeListValue(
778780 result : unknown ,
779781) : PromiseOrValue < ReadonlyArray < unknown > > {
780782 const itemType = returnType . ofType ;
783+ const errors = exeContext . errors ;
781784
782785 if ( isAsyncIterable ( result ) ) {
783786 const iterator = result [ Symbol . asyncIterator ] ( ) ;
@@ -839,13 +842,13 @@ function completeListValue(
839842 fieldNodes ,
840843 pathToArray ( itemPath ) ,
841844 ) ;
842- return handleFieldError ( error , itemType , exeContext ) ;
845+ return handleFieldError ( error , itemType , errors ) ;
843846 } ) ;
844847 }
845848 return completedItem ;
846849 } catch ( rawError ) {
847850 const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
848- return handleFieldError ( error , itemType , exeContext ) ;
851+ return handleFieldError ( error , itemType , errors ) ;
849852 }
850853 } ) ;
851854
@@ -989,9 +992,6 @@ function completeObjectValue(
989992 path : Path ,
990993 result : unknown ,
991994) : PromiseOrValue < ObjMap < unknown > > {
992- // Collect sub-fields to execute to complete this value.
993- const subFieldNodes = collectSubfields ( exeContext , returnType , fieldNodes ) ;
994-
995995 // If there is an isTypeOf predicate function, call it with the
996996 // current result. If isTypeOf returns false, then raise an error rather
997997 // than continuing execution.
@@ -1003,12 +1003,12 @@ function completeObjectValue(
10031003 if ( ! resolvedIsTypeOf ) {
10041004 throw invalidReturnTypeError ( returnType , result , fieldNodes ) ;
10051005 }
1006- return executeFields (
1006+ return collectAndExecuteSubfields (
10071007 exeContext ,
10081008 returnType ,
1009- result ,
1009+ fieldNodes ,
10101010 path ,
1011- subFieldNodes ,
1011+ result ,
10121012 ) ;
10131013 } ) ;
10141014 }
@@ -1018,7 +1018,13 @@ function completeObjectValue(
10181018 }
10191019 }
10201020
1021- return executeFields ( exeContext , returnType , result , path , subFieldNodes ) ;
1021+ return collectAndExecuteSubfields (
1022+ exeContext ,
1023+ returnType ,
1024+ fieldNodes ,
1025+ path ,
1026+ result ,
1027+ ) ;
10221028}
10231029
10241030function invalidReturnTypeError (
@@ -1032,6 +1038,19 @@ function invalidReturnTypeError(
10321038 ) ;
10331039}
10341040
1041+ function collectAndExecuteSubfields (
1042+ exeContext : ExecutionContext ,
1043+ returnType : GraphQLObjectType ,
1044+ fieldNodes : ReadonlyArray < FieldNode > ,
1045+ path : Path ,
1046+ result : unknown ,
1047+ ) : PromiseOrValue < ObjMap < unknown > > {
1048+ // Collect sub-fields to execute to complete this value.
1049+ const subFieldNodes = collectSubfields ( exeContext , returnType , fieldNodes ) ;
1050+
1051+ return executeFields ( exeContext , returnType , result , path , subFieldNodes ) ;
1052+ }
1053+
10351054/**
10361055 * If a resolveType function is not given, then a default resolve behavior is
10371056 * used which attempts two strategies:
0 commit comments