@@ -501,7 +501,6 @@ function executeField(
501501 fieldGroup : FieldGroup ,
502502 path : Path ,
503503) : PromiseOrValue < unknown > {
504- const errors = exeContext . errors ;
505504 const fieldName = fieldGroup [ 0 ] . name . value ;
506505 const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
507506 if ( ! fieldDef ) {
@@ -561,14 +560,14 @@ function executeField(
561560 // Note: we don't rely on a `catch` method, but we do expect "thenable"
562561 // to take a second callback for the error case.
563562 return completed . then ( undefined , ( rawError ) => {
564- const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
565- return handleFieldError ( error , returnType , errors ) ;
563+ handleFieldError ( rawError , exeContext , returnType , fieldGroup , path ) ;
564+ return null ;
566565 } ) ;
567566 }
568567 return completed ;
569568 } catch ( rawError ) {
570- const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
571- return handleFieldError ( error , returnType , errors ) ;
569+ handleFieldError ( rawError , exeContext , returnType , fieldGroup , path ) ;
570+ return null ;
572571 }
573572}
574573
@@ -600,10 +599,14 @@ export function buildResolveInfo(
600599}
601600
602601function handleFieldError (
603- error : GraphQLError ,
602+ rawError : unknown ,
603+ exeContext : ExecutionContext ,
604604 returnType : GraphQLOutputType ,
605- errors : Array < GraphQLError > ,
606- ) : null {
605+ fieldGroup : FieldGroup ,
606+ path : Path ,
607+ ) : void {
608+ const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
609+
607610 // If the field type is non-nullable, then it is resolved without any
608611 // protection from errors, however it still properly locates the error.
609612 if ( isNonNullType ( returnType ) ) {
@@ -612,8 +615,7 @@ function handleFieldError(
612615
613616 // Otherwise, error protection is applied, logging the error and resolving
614617 // a null value for this field if one is encountered.
615- errors . push ( error ) ;
616- return null ;
618+ exeContext . errors . push ( error ) ;
617619}
618620
619621/**
@@ -746,8 +748,8 @@ async function completePromisedValue(
746748 }
747749 return completed ;
748750 } catch ( rawError ) {
749- const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
750- return handleFieldError ( error , returnType , exeContext . errors ) ;
751+ handleFieldError ( rawError , exeContext , returnType , fieldGroup , path ) ;
752+ return null ;
751753 }
752754}
753755
@@ -763,7 +765,6 @@ async function completeAsyncIteratorValue(
763765 path : Path ,
764766 iterator : AsyncIterator < unknown > ,
765767) : Promise < ReadonlyArray < unknown > > {
766- const errors = exeContext . errors ;
767768 let containsPromise = false ;
768769 const completedResults : Array < unknown > = [ ] ;
769770 let index = 0 ;
@@ -778,16 +779,15 @@ async function completeAsyncIteratorValue(
778779 break ;
779780 }
780781 } catch ( rawError ) {
781- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
782- completedResults . push ( handleFieldError ( error , itemType , errors ) ) ;
782+ handleFieldError ( rawError , exeContext , itemType , fieldGroup , itemPath ) ;
783+ completedResults . push ( null ) ;
783784 break ;
784785 }
785786
786787 if (
787788 completeListItemValue (
788789 iteration . value ,
789790 completedResults ,
790- errors ,
791791 exeContext ,
792792 itemType ,
793793 fieldGroup ,
@@ -815,7 +815,6 @@ function completeListValue(
815815 result : unknown ,
816816) : PromiseOrValue < ReadonlyArray < unknown > > {
817817 const itemType = returnType . ofType ;
818- const errors = exeContext . errors ;
819818
820819 if ( isAsyncIterable ( result ) ) {
821820 const iterator = result [ Symbol . asyncIterator ] ( ) ;
@@ -850,7 +849,6 @@ function completeListValue(
850849 completeListItemValue (
851850 item ,
852851 completedResults ,
853- errors ,
854852 exeContext ,
855853 itemType ,
856854 fieldGroup ,
@@ -875,7 +873,6 @@ function completeListValue(
875873function completeListItemValue (
876874 item : unknown ,
877875 completedResults : Array < unknown > ,
878- errors : Array < GraphQLError > ,
879876 exeContext : ExecutionContext ,
880877 itemType : GraphQLOutputType ,
881878 fieldGroup : FieldGroup ,
@@ -912,12 +909,14 @@ function completeListItemValue(
912909 // to take a second callback for the error case.
913910 completedResults . push (
914911 completedItem . then ( undefined , ( rawError ) => {
915- const error = locatedError (
912+ handleFieldError (
916913 rawError ,
914+ exeContext ,
915+ itemType ,
917916 fieldGroup ,
918- pathToArray ( itemPath ) ,
917+ itemPath ,
919918 ) ;
920- return handleFieldError ( error , itemType , errors ) ;
919+ return null ;
921920 } ) ,
922921 ) ;
923922
@@ -926,9 +925,8 @@ function completeListItemValue(
926925
927926 completedResults . push ( completedItem ) ;
928927 } catch ( rawError ) {
929- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
930- const handledError = handleFieldError ( error , itemType , errors ) ;
931- completedResults . push ( handledError ) ;
928+ handleFieldError ( rawError , exeContext , itemType , fieldGroup , itemPath ) ;
929+ completedResults . push ( null ) ;
932930 }
933931
934932 return false ;
0 commit comments