@@ -1096,7 +1096,7 @@ function completeListValue(
1096
1096
// where the list contains no Promises by avoiding creating another Promise.
1097
1097
let containsPromise = false ;
1098
1098
let previousAsyncPayloadRecord = asyncPayloadRecord ;
1099
- const completedResults = [ ] ;
1099
+ const completedResults : Array < unknown > = [ ] ;
1100
1100
let index = 0 ;
1101
1101
for ( const item of result ) {
1102
1102
// No need to modify the info object containing the path,
@@ -1123,61 +1123,98 @@ function completeListValue(
1123
1123
continue ;
1124
1124
}
1125
1125
1126
- try {
1127
- let completedItem ;
1128
- if ( isPromise ( item ) ) {
1129
- completedItem = item . then ( ( resolved ) =>
1130
- completeValue (
1131
- exeContext ,
1132
- itemType ,
1133
- fieldNodes ,
1134
- info ,
1135
- itemPath ,
1136
- resolved ,
1137
- asyncPayloadRecord ,
1138
- ) ,
1139
- ) ;
1140
- } else {
1141
- completedItem = completeValue (
1126
+ if (
1127
+ completeListItemValue (
1128
+ item ,
1129
+ completedResults ,
1130
+ errors ,
1131
+ exeContext ,
1132
+ itemType ,
1133
+ fieldNodes ,
1134
+ info ,
1135
+ itemPath ,
1136
+ asyncPayloadRecord ,
1137
+ )
1138
+ ) {
1139
+ containsPromise = true ;
1140
+ }
1141
+
1142
+ index ++ ;
1143
+ }
1144
+
1145
+ return containsPromise ? Promise . all ( completedResults ) : completedResults ;
1146
+ }
1147
+
1148
+ /**
1149
+ * Complete a list item value by adding it to the completed results.
1150
+ *
1151
+ * Returns true if the value is a Promise.
1152
+ */
1153
+ function completeListItemValue (
1154
+ item : unknown ,
1155
+ completedResults : Array < unknown > ,
1156
+ errors : Array < GraphQLError > ,
1157
+ exeContext : ExecutionContext ,
1158
+ itemType : GraphQLOutputType ,
1159
+ fieldNodes : ReadonlyArray < FieldNode > ,
1160
+ info : GraphQLResolveInfo ,
1161
+ itemPath : Path ,
1162
+ asyncPayloadRecord ?: AsyncPayloadRecord ,
1163
+ ) : boolean {
1164
+ try {
1165
+ let completedItem ;
1166
+ if ( isPromise ( item ) ) {
1167
+ completedItem = item . then ( ( resolved ) =>
1168
+ completeValue (
1142
1169
exeContext ,
1143
1170
itemType ,
1144
1171
fieldNodes ,
1145
1172
info ,
1146
1173
itemPath ,
1147
- item ,
1174
+ resolved ,
1148
1175
asyncPayloadRecord ,
1149
- ) ;
1150
- }
1176
+ ) ,
1177
+ ) ;
1178
+ } else {
1179
+ completedItem = completeValue (
1180
+ exeContext ,
1181
+ itemType ,
1182
+ fieldNodes ,
1183
+ info ,
1184
+ itemPath ,
1185
+ item ,
1186
+ asyncPayloadRecord ,
1187
+ ) ;
1188
+ }
1151
1189
1152
- if ( isPromise ( completedItem ) ) {
1153
- containsPromise = true ;
1154
- // Note: we don't rely on a `catch` method, but we do expect "thenable"
1155
- // to take a second callback for the error case.
1156
- completedResults . push (
1157
- completedItem . then ( undefined , ( rawError ) => {
1158
- const error = locatedError (
1159
- rawError ,
1160
- fieldNodes ,
1161
- pathToArray ( itemPath ) ,
1162
- ) ;
1163
- const handledError = handleFieldError ( error , itemType , errors ) ;
1164
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1165
- return handledError ;
1166
- } ) ,
1167
- ) ;
1168
- } else {
1169
- completedResults . push ( completedItem ) ;
1170
- }
1171
- } catch ( rawError ) {
1172
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1173
- const handledError = handleFieldError ( error , itemType , errors ) ;
1174
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1175
- completedResults . push ( handledError ) ;
1190
+ if ( isPromise ( completedItem ) ) {
1191
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
1192
+ // to take a second callback for the error case.
1193
+ completedResults . push (
1194
+ completedItem . then ( undefined , ( rawError ) => {
1195
+ const error = locatedError (
1196
+ rawError ,
1197
+ fieldNodes ,
1198
+ pathToArray ( itemPath ) ,
1199
+ ) ;
1200
+ const handledError = handleFieldError ( error , itemType , errors ) ;
1201
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1202
+ return handledError ;
1203
+ } ) ,
1204
+ ) ;
1205
+
1206
+ return true ;
1176
1207
}
1177
- index ++ ;
1208
+
1209
+ completedResults . push ( completedItem ) ;
1210
+ } catch ( rawError ) {
1211
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1212
+ const handledError = handleFieldError ( error , itemType , errors ) ;
1213
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1214
+ completedResults . push ( handledError ) ;
1178
1215
}
1179
1216
1180
- return containsPromise ? Promise . all ( completedResults ) : completedResults ;
1217
+ return false ;
1181
1218
}
1182
1219
1183
1220
/**
0 commit comments