Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow async errors to bubble to AsyncIterable list items #3746

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/execution/__tests__/lists-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js';
import { parse } from '../../language/parser.js';

import type { GraphQLFieldResolver } from '../../type/definition.js';
import { GraphQLList, GraphQLObjectType } from '../../type/definition.js';
import {
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
} from '../../type/definition.js';
import { GraphQLString } from '../../type/scalars.js';
import { GraphQLSchema } from '../../type/schema.js';

Expand Down Expand Up @@ -101,7 +105,7 @@ describe('Execute: Accepts async iterables as list value', () => {
name: 'ObjectWrapper',
fields: {
index: {
type: GraphQLString,
type: new GraphQLNonNull(GraphQLString),
resolve,
},
},
Expand Down Expand Up @@ -202,7 +206,7 @@ describe('Execute: Accepts async iterables as list value', () => {
return Promise.resolve(index);
}),
).toDeepEqual({
data: { listField: [{ index: '0' }, { index: '1' }, { index: null }] },
data: { listField: [{ index: '0' }, { index: '1' }, null] },
errors: [
{
message: 'bad',
Expand Down
16 changes: 15 additions & 1 deletion src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,22 @@ async function completeAsyncIteratorValue(
);
if (isPromise(completedItem)) {
containsPromise = true;
// Note: we don't rely on a `catch` method, but we do expect "thenable"
// to take a second callback for the error case.
completedResults.push(
completedItem.then(undefined, (rawError) => {
const error = locatedError(
rawError,
fieldNodes,
pathToArray(fieldPath),
);
const handledError = handleFieldError(error, itemType, errors);
return handledError;
}),
);
} else {
completedResults.push(completedItem);
}
completedResults.push(completedItem);
} catch (rawError) {
completedResults.push(null);
const error = locatedError(
Expand Down