@@ -867,37 +867,57 @@ function completeAsyncIteratorValue(
867
867
fieldNodes : $ReadOnlyArray < FieldNode > ,
868
868
info : GraphQLResolveInfo ,
869
869
path : Path ,
870
- index : number ,
871
- completedResults : Array < mixed > ,
872
870
iterator : AsyncIterator < mixed > ,
873
871
) : Promise < $ReadOnlyArray < mixed >> {
874
- const fieldPath = addPath ( path , index , undefined ) ;
875
- return iterator . next ( ) . then (
876
- ( { value, done } ) => {
877
- if ( done ) {
878
- return completedResults ;
879
- }
880
- completedResults . push (
881
- completeValue ( exeContext , itemType , fieldNodes , info , fieldPath , value ) ,
882
- ) ;
883
- return completeAsyncIteratorValue (
884
- exeContext ,
885
- itemType ,
886
- fieldNodes ,
887
- info ,
888
- path ,
889
- index + 1 ,
890
- completedResults ,
891
- iterator ,
872
+ return new Promise ( ( resolve ) => {
873
+ function next ( index , completedResults ) {
874
+ const fieldPath = addPath ( path , index , undefined ) ;
875
+ iterator . next ( ) . then (
876
+ ( { value, done } ) => {
877
+ if ( done ) {
878
+ resolve ( completedResults ) ;
879
+ return ;
880
+ }
881
+ // TODO can the error checking logic be consolidated with completeListValue?
882
+ try {
883
+ completedResults . push (
884
+ completeValue (
885
+ exeContext ,
886
+ itemType ,
887
+ fieldNodes ,
888
+ info ,
889
+ fieldPath ,
890
+ value ,
891
+ ) ,
892
+ ) ;
893
+ } catch ( rawError ) {
894
+ completedResults . push ( null ) ;
895
+ const error = locatedError (
896
+ rawError ,
897
+ fieldNodes ,
898
+ pathToArray ( fieldPath ) ,
899
+ ) ;
900
+ handleFieldError ( error , itemType , exeContext ) ;
901
+ resolve ( completedResults ) ;
902
+ return ;
903
+ }
904
+
905
+ next ( index + 1 , completedResults ) ;
906
+ } ,
907
+ ( rawError ) => {
908
+ completedResults . push ( null ) ;
909
+ const error = locatedError (
910
+ rawError ,
911
+ fieldNodes ,
912
+ pathToArray ( fieldPath ) ,
913
+ ) ;
914
+ handleFieldError ( error , itemType , exeContext ) ;
915
+ resolve ( completedResults ) ;
916
+ } ,
892
917
) ;
893
- } ,
894
- ( rawError ) => {
895
- completedResults . push ( null ) ;
896
- const error = locatedError ( rawError , fieldNodes , pathToArray ( fieldPath ) ) ;
897
- handleFieldError ( error , itemType , exeContext ) ;
898
- return completedResults ;
899
- } ,
900
- ) ;
918
+ }
919
+ next ( 0 , [ ] ) ;
920
+ } ) ;
901
921
}
902
922
903
923
/**
@@ -923,8 +943,6 @@ function completeListValue(
923
943
fieldNodes ,
924
944
info ,
925
945
path ,
926
- 0 ,
927
- [ ] ,
928
946
iterator ,
929
947
) ;
930
948
}
0 commit comments