@@ -771,14 +771,27 @@ function resolveField(
771
771
info ,
772
772
) ;
773
773
774
- return completeValueCatchingError (
774
+ const completed = completeValueCatchingError (
775
775
exeContext ,
776
776
fieldDef . type ,
777
777
fieldNodes ,
778
778
info ,
779
779
path ,
780
780
result ,
781
781
) ;
782
+ const promise = getPromise ( completed ) ;
783
+ if ( promise ) {
784
+ return promise . then ( r => {
785
+ if ( r . errors && r . errors . length ) {
786
+ exeContext . errors . push . apply ( exeContext . errors , r . errors ) ;
787
+ }
788
+ return r . data ;
789
+ } ) ;
790
+ }
791
+ if ( completed . errors && completed . errors . length ) {
792
+ exeContext . errors . push . apply ( exeContext . errors , completed . errors ) ;
793
+ }
794
+ return completed . data ;
782
795
}
783
796
784
797
export function buildResolveInfo (
@@ -852,23 +865,18 @@ function completeValueCatchingError(
852
865
info: GraphQLResolveInfo,
853
866
path: ResponsePath,
854
867
result: mixed,
855
- ): mixed {
868
+ ): ExecutionPartialResult < mixed > {
856
869
// If the field type is non-nullable, then it is resolved without any
857
870
// protection from errors, however it still properly locates the error.
858
871
if ( isNonNullType ( returnType ) ) {
859
- const completed = completeValueWithLocatedError (
872
+ return completeValueWithLocatedError (
860
873
exeContext ,
861
874
returnType ,
862
875
fieldNodes ,
863
876
info ,
864
877
path ,
865
878
result ,
866
879
) ;
867
- const promise = getPromise ( completed ) ;
868
- if ( promise ) {
869
- return promise . then ( r => r . data ) ;
870
- }
871
- return completed . data ;
872
880
}
873
881
874
882
// Otherwise, error protection is applied, logging the error and resolving
@@ -888,17 +896,16 @@ function completeValueCatchingError(
888
896
// the rejection error and resolve to null.
889
897
// Note: we don't rely on a `catch` method, but we do expect "thenable"
890
898
// to take a second callback for the error case.
891
- return promise . then ( r => r . data ) . then ( undefined , error => {
892
- exeContext . errors . push ( error ) ;
893
- return null ;
894
- } ) ;
899
+ return promise . then ( undefined , error => ( {
900
+ data : null ,
901
+ errors : [ error ] ,
902
+ } ) ) ;
895
903
}
896
- return completed . data ;
904
+ return completed ;
897
905
} catch ( error ) {
898
906
// If `completeValueWithLocatedError` returned abruptly (threw an error),
899
907
// log the error and return null.
900
- exeContext . errors . push ( error ) ;
901
- return null ;
908
+ return { data : null , errors : [ error ] } ;
902
909
}
903
910
}
904
911
@@ -1107,8 +1114,22 @@ function completeListValue(
1107
1114
} ) ;
1108
1115
1109
1116
return containsPromise
1110
- ? Promise . all ( completedResults ) . then ( data => ( { data } ) )
1111
- : { data : completedResults } ;
1117
+ ? Promise . all ( completedResults ) . then ( r => flattenEPRs ( r ) )
1118
+ : flattenEPRs ( completedResults ) ;
1119
+ }
1120
+
1121
+ function flattenEPRs (
1122
+ eprs : $ReadOnlyArray < ExecutionPartialResult < mixed >> ,
1123
+ ) : ExecutionPartialResult < mixed > {
1124
+ const errors = [ ] ;
1125
+ const data = [ ] ;
1126
+ forEach ( ( eprs : any ) , item => {
1127
+ data . push ( item . data ) ;
1128
+ if ( item . errors && item . errors . length ) {
1129
+ errors . push . apply ( errors , item . errors ) ;
1130
+ }
1131
+ } ) ;
1132
+ return { data , errors } ;
1112
1133
}
1113
1134
1114
1135
/**
0 commit comments