Skip to content

Commit

Permalink
fix: async errors may bubble to AsyncIterable list items
Browse files Browse the repository at this point in the history
fixes test so that `completeValue` rejects for the AsyncIterable and not just for the nested object.
  • Loading branch information
yaacovCR committed Sep 22, 2022
1 parent 269d6aa commit efc7ee6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
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

0 comments on commit efc7ee6

Please sign in to comment.