@@ -919,55 +919,45 @@ function completeValue(
919
919
}
920
920
921
921
/**
922
- * Complete a async iterable value by completing each item in the list with
923
- * the inner type
922
+ * Complete a async iterator value by completing the result and calling
923
+ * recursively until all the results are completed.
924
924
*/
925
- function completeAsyncIterableValue (
925
+ function completeAsyncIteratorValue (
926
926
exeContext : ExecutionContext ,
927
- returnType : GraphQLList < GraphQLOutputType > ,
927
+ itemType : GraphQLOutputType ,
928
928
fieldNodes : $ReadOnlyArray < FieldNode > ,
929
929
info: GraphQLResolveInfo,
930
930
path: Path,
931
- result: AsyncIterable< mixed > ,
931
+ index: number,
932
+ completedResults: Array< mixed > ,
933
+ iterator: AsyncIterator< mixed > ,
932
934
): Promise< $ReadOnlyArray < mixed > > {
933
- // $FlowFixMe
934
- const iteratorMethod = result [ SYMBOL_ASYNC_ITERATOR ] ;
935
- const iterator = iteratorMethod . call ( result ) ;
936
-
937
- const completedResults = [ ] ;
938
- let index = 0 ;
939
-
940
- const itemType = returnType . ofType ;
941
-
942
- function handleNext ( ) {
943
- const fieldPath = addPath ( path , index ) ;
944
- return iterator . next ( ) . then (
945
- ( { value, done } ) => {
946
- if ( done ) {
947
- return completedResults ;
948
- }
949
- completedResults . push (
950
- completeValue (
951
- exeContext ,
952
- itemType ,
953
- fieldNodes ,
954
- info ,
955
- fieldPath ,
956
- value ,
957
- ) ,
958
- ) ;
959
- index ++ ;
960
- return handleNext ( ) ;
961
- } ,
962
- ( error ) => {
963
- completedResults . push ( null ) ;
964
- handleFieldError ( error , fieldNodes , fieldPath , itemType , exeContext ) ;
935
+ const fieldPath = addPath ( path , index ) ;
936
+ return iterator . next ( ) . then (
937
+ ( { value, done } ) => {
938
+ if ( done ) {
965
939
return completedResults ;
966
- } ,
967
- ) ;
968
- }
969
-
970
- return handleNext ( ) ;
940
+ }
941
+ completedResults . push (
942
+ completeValue ( exeContext , itemType , fieldNodes , info , fieldPath , value ) ,
943
+ ) ;
944
+ return completeAsyncIteratorValue (
945
+ exeContext ,
946
+ itemType ,
947
+ fieldNodes ,
948
+ info ,
949
+ path ,
950
+ index + 1 ,
951
+ completedResults ,
952
+ iterator ,
953
+ ) ;
954
+ } ,
955
+ ( error ) => {
956
+ completedResults . push ( null ) ;
957
+ handleFieldError ( error , fieldNodes , fieldPath , itemType , exeContext ) ;
958
+ return completedResults ;
959
+ } ,
960
+ ) ;
971
961
}
972
962
973
963
/**
@@ -982,14 +972,21 @@ function completeListValue(
982
972
path: Path,
983
973
result: mixed,
984
974
): PromiseOrValue< $ReadOnlyArray < mixed > > {
975
+ const itemType = returnType . ofType ;
976
+
985
977
if ( isAsyncIterable ( result ) ) {
986
- return completeAsyncIterableValue (
978
+ const iteratorMethod = result [ SYMBOL_ASYNC_ITERATOR ] ;
979
+ const iterator = iteratorMethod . call ( result ) ;
980
+
981
+ return completeAsyncIteratorValue (
987
982
exeContext ,
988
- returnType ,
983
+ itemType ,
989
984
fieldNodes ,
990
985
info ,
991
986
path ,
992
- result ,
987
+ 0 ,
988
+ [ ] ,
989
+ iterator ,
993
990
) ;
994
991
}
995
992
@@ -1001,7 +998,6 @@ function completeListValue(
1001
998
1002
999
// This is specified as a simple map, however we're optimizing the path
1003
1000
// where the list contains no Promises by avoiding creating another Promise.
1004
- const itemType = returnType.ofType;
1005
1001
let containsPromise = false ;
1006
1002
const completedResults = arrayFrom ( result , ( item , index ) => {
1007
1003
// No need to modify the info object containing the path,
0 commit comments