Skip to content

remove additional tick from executeStreamIterator #3799

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

Closed
wants to merge 3 commits into from
Closed
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
102 changes: 63 additions & 39 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,56 @@ describe('Execute: stream directive', () => {
},
]);
});
it('Can stream a field that returns a list of promises with nested promises', async () => {
const document = parse(`
query {
friendList @stream(initialCount: 2) {
name
id
}
}
`);
const result = await complete(document, {
friendList: () =>
friends.map((f) =>
Promise.resolve({
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 @@ -531,11 +581,6 @@ describe('Execute: stream directive', () => {
},
],
},
],
hasNext: true,
},
{
incremental: [
{
items: [{ name: 'Leia', id: '3' }],
path: ['friendList', 2],
Expand Down Expand Up @@ -633,9 +678,6 @@ describe('Execute: stream directive', () => {
path: ['friendList', 2],
},
],
hasNext: true,
},
{
hasNext: false,
},
]);
Expand Down Expand Up @@ -675,7 +717,7 @@ describe('Execute: stream directive', () => {
}
}
`);
const result = await completeAsync(document, 3, {
const result = await completeAsync(document, 2, {
async *friendList() {
yield await Promise.resolve(friends[0]);
yield await Promise.resolve(friends[1]);
Expand Down Expand Up @@ -704,10 +746,9 @@ describe('Execute: stream directive', () => {
path: ['friendList', 2],
},
],
hasNext: true,
hasNext: false,
},
},
{ done: false, value: { hasNext: false } },
{ done: true, value: undefined },
]);
});
Expand Down Expand Up @@ -984,11 +1025,6 @@ describe('Execute: stream directive', () => {
},
],
},
],
hasNext: true,
},
{
incremental: [
{
items: [{ nonNullName: 'Han' }],
path: ['friendList', 2],
Expand Down Expand Up @@ -1174,9 +1210,6 @@ describe('Execute: stream directive', () => {
],
},
],
hasNext: true,
},
{
hasNext: false,
},
]);
Expand All @@ -1200,25 +1233,19 @@ describe('Execute: stream directive', () => {
} /* c8 ignore stop */,
},
});
expectJSON(result).toDeepEqual([
{
errors: [
{
message:
'Cannot return null for non-nullable field NestedObject.nonNullScalarField.',
locations: [{ line: 4, column: 11 }],
path: ['nestedObject', 'nonNullScalarField'],
},
],
data: {
nestedObject: null,
expectJSON(result).toDeepEqual({
errors: [
{
message:
'Cannot return null for non-nullable field NestedObject.nonNullScalarField.',
locations: [{ line: 4, column: 11 }],
path: ['nestedObject', 'nonNullScalarField'],
},
hasNext: true,
},
{
hasNext: false,
],
data: {
nestedObject: null,
},
]);
});
});
it('Filters payloads that are nulled by a later synchronous error', async () => {
const document = parse(`
Expand Down Expand Up @@ -1359,9 +1386,6 @@ describe('Execute: stream directive', () => {
],
},
],
hasNext: true,
},
{
hasNext: false,
},
]);
Expand Down
Loading