Skip to content

Commit 6180941

Browse files
committed
top level query defer test
1 parent 91e9366 commit 6180941

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/__tests__/starWarsDeferredQuery-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,43 @@ describe('Star Wars Query Deferred Tests', () => {
8080
},
8181
});
8282
});
83+
it('Can defer a fragment on the top level Query field', async () => {
84+
const query = `
85+
query HeroNameQuery {
86+
...QueryFragment @defer(label: "DeferQuery")
87+
}
88+
fragment QueryFragment on Query {
89+
hero {
90+
id
91+
}
92+
}
93+
`;
94+
95+
const result = await graphql(StarWarsSchemaDeferStreamEnabled, query);
96+
const { patches: patchesIterable, ...initial } = result;
97+
expect(initial).to.deep.equal({
98+
data: {},
99+
});
100+
101+
const patches = [];
102+
103+
if (patchesIterable) {
104+
await forAwaitEach(patchesIterable, patch => {
105+
patches.push(patch);
106+
});
107+
}
108+
109+
expect(patches).to.have.lengthOf(1);
110+
expect(patches[0]).to.deep.equal({
111+
label: 'DeferQuery',
112+
path: [],
113+
data: {
114+
hero: {
115+
id: '2001',
116+
},
117+
},
118+
});
119+
});
83120
});
84121

85122
// TODO

0 commit comments

Comments
 (0)