Skip to content

Commit

Permalink
asyncIterable: locate async iterator errors to the collection (graphq…
Browse files Browse the repository at this point in the history
…l#3899)

Currently, they are presented as errors in the next pending item.

Of course, there may or not be a next pending item; there may not be a
way to definitively know the reason for the error, such that the error
is a function of a problem with the collection itself.

As discussed in a prior incremental delivery WG meeting, this must be
changed for both the non-streaming and streaming cases; this PR makes
the minor adjustments addressing both cases.
  • Loading branch information
yaacovCR authored May 23, 2023
1 parent e17a089 commit bd558cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/execution/__tests__/lists-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ describe('Execute: Accepts async iterables as list value', () => {
}

expectJSON(await complete({ listField })).toDeepEqual({
data: { listField: ['two', '4', null] },
data: { listField: null },
errors: [
{
message: 'bad',
locations: [{ line: 1, column: 3 }],
path: ['listField', 2],
path: ['listField'],
},
],
});
Expand Down
8 changes: 4 additions & 4 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,11 @@ describe('Execute: stream directive', () => {
{
message: 'bad',
locations: [{ line: 3, column: 9 }],
path: ['friendList', 1],
path: ['friendList'],
},
],
data: {
friendList: [{ name: 'Luke', id: '1' }, null],
friendList: null,
},
});
});
Expand Down Expand Up @@ -764,13 +764,13 @@ describe('Execute: stream directive', () => {
{
incremental: [
{
items: [null],
items: null,
path: ['friendList', 1],
errors: [
{
message: 'bad',
locations: [{ line: 3, column: 9 }],
path: ['friendList', 1],
path: ['friendList'],
},
],
},
Expand Down
24 changes: 4 additions & 20 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,16 +1093,7 @@ async function completeAsyncIteratorValue(
break;
}
} catch (rawError) {
handleFieldError(
rawError,
exeContext,
itemType,
fieldGroup,
itemPath,
incrementalDataRecord,
);
completedResults.push(null);
break;
throw locatedError(rawError, fieldGroup, pathToArray(path));
}

if (
Expand Down Expand Up @@ -1954,6 +1945,7 @@ async function executeStreamAsyncIteratorItem(
info: GraphQLResolveInfo,
itemType: GraphQLOutputType,
incrementalDataRecord: StreamItemsRecord,
path: Path,
itemPath: Path,
): Promise<IteratorResult<unknown>> {
let item;
Expand All @@ -1965,16 +1957,7 @@ async function executeStreamAsyncIteratorItem(
}
item = value;
} catch (rawError) {
handleFieldError(
rawError,
exeContext,
itemType,
fieldGroup,
itemPath,
incrementalDataRecord,
);
// don't continue if async iterator throws
return { done: true, value: null };
throw locatedError(rawError, fieldGroup, pathToArray(path));
}
let completedItem;
try {
Expand Down Expand Up @@ -2051,6 +2034,7 @@ async function executeStreamAsyncIterator(
info,
itemType,
incrementalDataRecord,
path,
itemPath,
);
} catch (error) {
Expand Down

0 comments on commit bd558cb

Please sign in to comment.