Skip to content

Commit 84797fb

Browse files
authored
fix: allow async errors to bubble to AsyncIterable list items (#3746)
1 parent 042002c commit 84797fb

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/execution/__tests__/lists-test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js';
88
import { parse } from '../../language/parser.js';
99

1010
import type { GraphQLFieldResolver } from '../../type/definition.js';
11-
import { GraphQLList, GraphQLObjectType } from '../../type/definition.js';
11+
import {
12+
GraphQLList,
13+
GraphQLNonNull,
14+
GraphQLObjectType,
15+
} from '../../type/definition.js';
1216
import { GraphQLString } from '../../type/scalars.js';
1317
import { GraphQLSchema } from '../../type/schema.js';
1418

@@ -101,7 +105,7 @@ describe('Execute: Accepts async iterables as list value', () => {
101105
name: 'ObjectWrapper',
102106
fields: {
103107
index: {
104-
type: GraphQLString,
108+
type: new GraphQLNonNull(GraphQLString),
105109
resolve,
106110
},
107111
},
@@ -202,7 +206,7 @@ describe('Execute: Accepts async iterables as list value', () => {
202206
return Promise.resolve(index);
203207
}),
204208
).toDeepEqual({
205-
data: { listField: [{ index: '0' }, { index: '1' }, { index: null }] },
209+
data: { listField: [{ index: '0' }, { index: '1' }, null] },
206210
errors: [
207211
{
208212
message: 'bad',

src/execution/execute.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,22 @@ async function completeAsyncIteratorValue(
10171017
);
10181018
if (isPromise(completedItem)) {
10191019
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(fieldPath),
1028+
);
1029+
const handledError = handleFieldError(error, itemType, errors);
1030+
return handledError;
1031+
}),
1032+
);
1033+
} else {
1034+
completedResults.push(completedItem);
10201035
}
1021-
completedResults.push(completedItem);
10221036
} catch (rawError) {
10231037
completedResults.push(null);
10241038
const error = locatedError(

0 commit comments

Comments
 (0)