Skip to content

Commit c78bc1d

Browse files
committed
polish(incremental): improve IncrementalPublisher return test
Use a stream that never resolves to better demonstrate how there will be a definite pending promise. Calling return on the underlying graph flushes the nextQueue anyway.
1 parent f6227a8 commit c78bc1d

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/execution/__tests__/stream-test.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,16 +2331,12 @@ describe('Execute: stream directive', () => {
23312331
});
23322332
it('Returns underlying async iterables when returned generator is returned', async () => {
23332333
let returned = false;
2334-
let index = 0;
23352334
const iterable = {
23362335
[Symbol.asyncIterator]: () => ({
2337-
next: () => {
2338-
const friend = friends[index++];
2339-
if (friend == null) {
2340-
return Promise.resolve({ done: true, value: undefined });
2341-
}
2342-
return Promise.resolve({ done: false, value: friend });
2343-
},
2336+
next: () =>
2337+
new Promise(() => {
2338+
/* never resolves */
2339+
}),
23442340
return: () => {
23452341
returned = true;
23462342
},
@@ -2349,11 +2345,8 @@ describe('Execute: stream directive', () => {
23492345

23502346
const document = parse(`
23512347
query {
2352-
friendList @stream(initialCount: 1) {
2348+
friendList @stream(initialCount: 0) {
23532349
id
2354-
... @defer {
2355-
name
2356-
}
23572350
}
23582351
}
23592352
`);
@@ -2371,21 +2364,16 @@ describe('Execute: stream directive', () => {
23712364
const result1 = executeResult.initialResult;
23722365
expectJSON(result1).toDeepEqual({
23732366
data: {
2374-
friendList: [
2375-
{
2376-
id: '1',
2377-
},
2378-
],
2367+
friendList: [],
23792368
},
2380-
pending: [
2381-
{ id: '0', path: ['friendList', 0] },
2382-
{ id: '1', path: ['friendList'] },
2383-
],
2369+
pending: [{ id: '0', path: ['friendList'] }],
23842370
hasNext: true,
23852371
});
2372+
2373+
const result2Promise = iterator.next();
23862374
const returnPromise = iterator.return();
23872375

2388-
const result2 = await iterator.next();
2376+
const result2 = await result2Promise;
23892377
expectJSON(result2).toDeepEqual({
23902378
done: true,
23912379
value: undefined,

0 commit comments

Comments
 (0)