Skip to content
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
137 changes: 137 additions & 0 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,54 @@ describe('Execute: stream directive', () => {
},
]);
});
it('Can stream a field that returns a list with nested promises', async () => {
const document = parse(`
query {
friendList @stream(initialCount: 2) {
name
id
}
}
`);
const result = await complete(document, {
friendList: () =>
friends.map((f) => ({
name: Promise.resolve(f.name),
id: Promise.resolve(f.id),
})),
});
expectJSON(result).toDeepEqual([
{
data: {
friendList: [
{
name: 'Luke',
id: '1',
},
{
name: 'Han',
id: '2',
},
],
},
hasNext: true,
},
{
incremental: [
{
items: [
{
name: 'Leia',
id: '3',
},
],
path: ['friendList', 2],
},
],
hasNext: false,
},
]);
});
it('Handles rejections in a field that returns a list of promises before initialCount is reached', async () => {
const document = parse(`
query {
Expand Down Expand Up @@ -901,6 +949,55 @@ describe('Execute: stream directive', () => {
},
]);
});
it('Handles nested async errors thrown by completeValue after initialCount is reached', async () => {
const document = parse(`
query {
friendList @stream(initialCount: 1) {
nonNullName
}
}
`);
const result = await complete(document, {
friendList: () => [
{ nonNullName: Promise.resolve(friends[0].name) },
{ nonNullName: Promise.reject(new Error('Oops')) },
{ nonNullName: Promise.resolve(friends[1].name) },
],
});
expectJSON(result).toDeepEqual([
{
data: {
friendList: [{ nonNullName: 'Luke' }],
},
hasNext: true,
},
{
incremental: [
{
items: [null],
path: ['friendList', 1],
errors: [
{
message: 'Oops',
locations: [{ line: 4, column: 11 }],
path: ['friendList', 1, 'nonNullName'],
},
],
},
],
hasNext: true,
},
{
incremental: [
{
items: [{ nonNullName: 'Han' }],
path: ['friendList', 2],
},
],
hasNext: false,
},
]);
});
it('Handles async errors thrown by completeValue after initialCount is reached for a non-nullable list', async () => {
const document = parse(`
query {
Expand Down Expand Up @@ -943,6 +1040,46 @@ describe('Execute: stream directive', () => {
},
]);
});
it('Handles nested async errors thrown by completeValue after initialCount is reached for a non-nullable list', async () => {
const document = parse(`
query {
nonNullFriendList @stream(initialCount: 1) {
nonNullName
}
}
`);
const result = await complete(document, {
nonNullFriendList: () => [
{ nonNullName: Promise.resolve(friends[0].name) },
{ nonNullName: Promise.reject(new Error('Oops')) },
{ nonNullName: Promise.resolve(friends[1].name) },
],
});
expectJSON(result).toDeepEqual([
{
data: {
nonNullFriendList: [{ nonNullName: 'Luke' }],
},
hasNext: true,
},
{
incremental: [
{
items: null,
path: ['nonNullFriendList', 1],
errors: [
{
message: 'Oops',
locations: [{ line: 4, column: 11 }],
path: ['nonNullFriendList', 1, 'nonNullName'],
},
],
},
],
hasNext: false,
},
]);
});
it('Handles async errors thrown by completeValue after initialCount is reached from async iterable', async () => {
const document = parse(`
query {
Expand Down
Loading