@@ -853,55 +853,45 @@ function completeValue(
853853}
854854
855855/**
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.
858858 */
859- function completeAsyncIterableValue (
859+ function completeAsyncIteratorValue (
860860 exeContext : ExecutionContext ,
861- returnType : GraphQLList < GraphQLOutputType > ,
861+ itemType : GraphQLOutputType ,
862862 fieldNodes : $ReadOnlyArray < FieldNode > ,
863863 info : GraphQLResolveInfo ,
864864 path : Path ,
865- result : AsyncIterable < mixed > ,
865+ index : number ,
866+ completedResults : Array < mixed > ,
867+ iterator : AsyncIterator < mixed > ,
866868) : 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 ) {
899873 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+ ) ;
905895}
906896
907897/**
@@ -916,14 +906,21 @@ function completeListValue(
916906 path : Path ,
917907 result : mixed ,
918908) : PromiseOrValue < $ReadOnlyArray < mixed >> {
909+ const itemType = returnType . ofType ;
910+
919911 if ( isAsyncIterable ( result ) ) {
920- return completeAsyncIterableValue (
912+ const iteratorMethod = result [ SYMBOL_ASYNC_ITERATOR ] ;
913+ const iterator = iteratorMethod . call ( result ) ;
914+
915+ return completeAsyncIteratorValue (
921916 exeContext ,
922- returnType ,
917+ itemType ,
923918 fieldNodes ,
924919 info ,
925920 path ,
926- result ,
921+ 0 ,
922+ [ ] ,
923+ iterator ,
927924 ) ;
928925 }
929926
@@ -935,7 +932,6 @@ function completeListValue(
935932
936933 // This is specified as a simple map, however we're optimizing the path
937934 // where the list contains no Promises by avoiding creating another Promise.
938- const itemType = returnType . ofType ;
939935 let containsPromise = false ;
940936 const completedResults = arrayFrom ( result , ( item , index ) => {
941937 // No need to modify the info object containing the path,
0 commit comments