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