@@ -972,7 +972,7 @@ async function completeAsyncIteratorValue(
972
972
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
973
973
const stream = getStreamValues ( exeContext , fieldNodes , path ) ;
974
974
let containsPromise = false ;
975
- const completedResults = [ ] ;
975
+ const completedResults : Array < unknown > = [ ] ;
976
976
let index = 0 ;
977
977
// eslint-disable-next-line no-constant-condition
978
978
while ( true ) {
@@ -997,58 +997,34 @@ async function completeAsyncIteratorValue(
997
997
}
998
998
999
999
const itemPath = addPath ( path , index , undefined ) ;
1000
+ let iteration ;
1000
1001
try {
1001
1002
// eslint-disable-next-line no-await-in-loop
1002
- const { value , done } = await iterator . next ( ) ;
1003
- if ( done ) {
1003
+ iteration = await iterator . next ( ) ;
1004
+ if ( iteration . done ) {
1004
1005
break ;
1005
1006
}
1006
-
1007
- try {
1008
- // TODO can the error checking logic be consolidated with completeListValue?
1009
- const completedItem = completeValue (
1010
- exeContext ,
1011
- itemType ,
1012
- fieldNodes ,
1013
- info ,
1014
- itemPath ,
1015
- value ,
1016
- asyncPayloadRecord ,
1017
- ) ;
1018
- if ( isPromise ( completedItem ) ) {
1019
- containsPromise = true ;
1020
- // Note: we don't rely on a `catch` method, but we do expect "thenable"
1021
- // to take a second callback for the error case.
1022
- completedResults . push (
1023
- completedItem . then ( undefined , ( rawError ) => {
1024
- const error = locatedError (
1025
- rawError ,
1026
- fieldNodes ,
1027
- pathToArray ( itemPath ) ,
1028
- ) ;
1029
- const handledError = handleFieldError ( error , itemType , errors ) ;
1030
- filterSubsequentPayloads (
1031
- exeContext ,
1032
- itemPath ,
1033
- asyncPayloadRecord ,
1034
- ) ;
1035
- return handledError ;
1036
- } ) ,
1037
- ) ;
1038
- } else {
1039
- completedResults . push ( completedItem ) ;
1040
- }
1041
- } catch ( rawError ) {
1042
- completedResults . push ( null ) ;
1043
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1044
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1045
- handleFieldError ( error , itemType , errors ) ;
1046
- }
1047
1007
} catch ( rawError ) {
1048
1008
const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1049
1009
completedResults . push ( handleFieldError ( error , itemType , errors ) ) ;
1050
1010
break ;
1051
1011
}
1012
+
1013
+ if (
1014
+ completeListItemValue (
1015
+ iteration . value ,
1016
+ completedResults ,
1017
+ errors ,
1018
+ exeContext ,
1019
+ itemType ,
1020
+ fieldNodes ,
1021
+ info ,
1022
+ itemPath ,
1023
+ asyncPayloadRecord ,
1024
+ )
1025
+ ) {
1026
+ containsPromise = true ;
1027
+ }
1052
1028
index += 1 ;
1053
1029
}
1054
1030
return containsPromise ? Promise . all ( completedResults ) : completedResults ;
0 commit comments