@@ -853,55 +853,45 @@ function completeValue(
853
853
}
854
854
855
855
/**
856
- * Complete a async iterable value by completing each item in the list with
857
- * the inner type
856
+ * Complete a async iterator value by completing the result and calling
857
+ * recursively until all the results are completed.
858
858
*/
859
- function completeAsyncIterableValue (
859
+ function completeAsyncIteratorValue (
860
860
exeContext : ExecutionContext ,
861
- returnType : GraphQLList < GraphQLOutputType > ,
861
+ itemType : GraphQLOutputType ,
862
862
fieldNodes : $ReadOnlyArray < FieldNode > ,
863
863
info : GraphQLResolveInfo ,
864
864
path : Path ,
865
- result : AsyncIterable < mixed > ,
865
+ index : number ,
866
+ completedResults : Array < mixed > ,
867
+ iterator : AsyncIterator < mixed > ,
866
868
) : Promise < $ReadOnlyArray < mixed >> {
867
- // $FlowFixMe
868
- const iteratorMethod = result [ SYMBOL_ASYNC_ITERATOR ] ;
869
- const iterator = iteratorMethod . call ( result ) ;
870
-
871
- const completedResults = [ ] ;
872
- let index = 0 ;
873
-
874
- const itemType = returnType . ofType ;
875
-
876
- function handleNext ( ) {
877
- const fieldPath = addPath ( path , index ) ;
878
- return iterator . next ( ) . then (
879
- ( { value, done } ) => {
880
- if ( done ) {
881
- return completedResults ;
882
- }
883
- completedResults . push (
884
- completeValue (
885
- exeContext ,
886
- itemType ,
887
- fieldNodes ,
888
- info ,
889
- fieldPath ,
890
- value ,
891
- ) ,
892
- ) ;
893
- index ++ ;
894
- return handleNext ( ) ;
895
- } ,
896
- ( error ) => {
897
- completedResults . push ( null ) ;
898
- handleFieldError ( error , fieldNodes , fieldPath , itemType , exeContext ) ;
869
+ const fieldPath = addPath ( path , index ) ;
870
+ return iterator . next ( ) . then (
871
+ ( { value, done } ) => {
872
+ if ( done ) {
899
873
return completedResults ;
900
- } ,
901
- ) ;
902
- }
903
-
904
- return handleNext ( ) ;
874
+ }
875
+ completedResults . push (
876
+ completeValue ( exeContext , itemType , fieldNodes , info , fieldPath , value ) ,
877
+ ) ;
878
+ return completeAsyncIteratorValue (
879
+ exeContext ,
880
+ itemType ,
881
+ fieldNodes ,
882
+ info ,
883
+ path ,
884
+ index + 1 ,
885
+ completedResults ,
886
+ iterator ,
887
+ ) ;
888
+ } ,
889
+ ( error ) => {
890
+ completedResults . push ( null ) ;
891
+ handleFieldError ( error , fieldNodes , fieldPath , itemType , exeContext ) ;
892
+ return completedResults ;
893
+ } ,
894
+ ) ;
905
895
}
906
896
907
897
/**
@@ -916,14 +906,21 @@ function completeListValue(
916
906
path : Path ,
917
907
result : mixed ,
918
908
) : PromiseOrValue < $ReadOnlyArray < mixed >> {
909
+ const itemType = returnType . ofType ;
910
+
919
911
if ( isAsyncIterable ( result ) ) {
920
- return completeAsyncIterableValue (
912
+ const iteratorMethod = result [ SYMBOL_ASYNC_ITERATOR ] ;
913
+ const iterator = iteratorMethod . call ( result ) ;
914
+
915
+ return completeAsyncIteratorValue (
921
916
exeContext ,
922
- returnType ,
917
+ itemType ,
923
918
fieldNodes ,
924
919
info ,
925
920
path ,
926
- result ,
921
+ 0 ,
922
+ [ ] ,
923
+ iterator ,
927
924
) ;
928
925
}
929
926
@@ -935,7 +932,6 @@ function completeListValue(
935
932
936
933
// This is specified as a simple map, however we're optimizing the path
937
934
// where the list contains no Promises by avoiding creating another Promise.
938
- const itemType = returnType . ofType ;
939
935
let containsPromise = false ;
940
936
const completedResults = arrayFrom ( result , ( item , index ) => {
941
937
// No need to modify the info object containing the path,
0 commit comments