Skip to content

Commit 88cc98b

Browse files
committed
add new tests
1 parent 79a69a5 commit 88cc98b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/execution/__tests__/defer-test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,40 @@ describe('Execute: defer directive', () => {
476476
});
477477
});
478478

479+
it('Emits children of empty defer fragments', async () => {
480+
const document = parse(`
481+
query HeroNameQuery {
482+
hero {
483+
... @defer {
484+
... @defer {
485+
name
486+
}
487+
}
488+
}
489+
}
490+
`);
491+
const result = await complete(document);
492+
expectJSON(result).toDeepEqual([
493+
{
494+
data: {
495+
hero: {},
496+
},
497+
pending: [{ id: '0', path: ['hero'] }],
498+
hasNext: true,
499+
},
500+
{
501+
pending: [{ id: '1', path: ['hero'] }],
502+
completed: [{ id: '0' }],
503+
hasNext: true,
504+
},
505+
{
506+
incremental: [{ data: { name: 'Luke' }, id: '1' }],
507+
completed: [{ id: '1' }],
508+
hasNext: false,
509+
},
510+
]);
511+
});
512+
479513
it('Can separately emit defer fragments with different labels with varying fields', async () => {
480514
const document = parse(`
481515
query HeroNameQuery {
@@ -760,13 +794,38 @@ describe('Execute: defer directive', () => {
760794
],
761795
hasNext: true,
762796
},
797+
// TODO: these pending notifications and the subsequent payloads are all empty
798+
// fixed by https://github.com/graphql/graphql-js/pull/3993
763799
{
800+
pending: [
801+
{ id: '3', path: ['hero', 'friends', 0] },
802+
{ id: '4', path: ['hero', 'friends', 1] },
803+
{ id: '5', path: ['hero', 'friends', 2] },
804+
],
764805
incremental: [
765806
{ data: { id: '2', name: 'Han' }, id: '0' },
766807
{ data: { id: '3', name: 'Leia' }, id: '1' },
767808
{ data: { id: '4', name: 'C-3PO' }, id: '2' },
768809
],
769810
completed: [{ id: '0' }, { id: '1' }, { id: '2' }],
811+
hasNext: true,
812+
},
813+
{
814+
pending: [
815+
{ id: '6', path: ['hero', 'friends', 0] },
816+
{ id: '7', path: ['hero', 'friends', 1] },
817+
{ id: '8', path: ['hero', 'friends', 2] },
818+
],
819+
completed: [{ id: '3' }, { id: '4' }, { id: '5' }],
820+
hasNext: true,
821+
},
822+
{
823+
pending: [
824+
{ id: '9', path: ['hero', 'friends', 0] },
825+
{ id: '10', path: ['hero', 'friends', 1] },
826+
{ id: '11', path: ['hero', 'friends', 2] },
827+
],
828+
completed: [{ id: '6' }, { id: '7' }, { id: '8' }],
770829
hasNext: false,
771830
},
772831
]);

0 commit comments

Comments
 (0)