Skip to content

Commit 267153e

Browse files
committed
additional stream test
1 parent 58e9324 commit 267153e

File tree

1 file changed

+100
-68
lines changed

1 file changed

+100
-68
lines changed

src/__tests__/starWarsStreamQuery-test.js

Lines changed: 100 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,39 @@ describe('Star Wars Query Stream Tests', () => {
4646
},
4747
});
4848
});
49+
it('Can disable @stream using if argument', async () => {
50+
const query = `
51+
query HeroFriendsQuery {
52+
hero {
53+
friends @stream(initial_count: 0, label: "HeroFriends", if: false) {
54+
id
55+
name
56+
}
57+
}
58+
}
59+
`;
60+
const result = await graphql(StarWarsSchemaDeferStreamEnabled, query);
61+
expect(result).to.deep.equal({
62+
data: {
63+
hero: {
64+
friends: [
65+
{
66+
id: '1000',
67+
name: 'Luke Skywalker',
68+
},
69+
{
70+
id: '1002',
71+
name: 'Han Solo',
72+
},
73+
{
74+
id: '1003',
75+
name: 'Leia Organa',
76+
},
77+
],
78+
},
79+
},
80+
});
81+
});
4982
});
5083

5184
describe('Basic Queries', () => {
@@ -97,84 +130,83 @@ describe('Star Wars Query Stream Tests', () => {
97130
},
98131
});
99132
});
100-
});
101-
102-
it('Can @stream multiple selections on the same field', async () => {
103-
const query = `
104-
query HeroFriendsQuery {
105-
hero {
106-
friends {
107-
id
133+
it('Can @stream multiple selections on the same field', async () => {
134+
const query = `
135+
query HeroFriendsQuery {
136+
hero {
137+
friends {
138+
id
139+
}
140+
...FriendsName
141+
...FriendsAppearsIn
108142
}
109-
...FriendsName
110-
...FriendsAppearsIn
111143
}
112-
}
113-
fragment FriendsName on Character {
114-
friends @stream(label: "nameLabel", initial_count: 1) {
115-
name
144+
fragment FriendsName on Character {
145+
friends @stream(label: "nameLabel", initial_count: 1) {
146+
name
147+
}
116148
}
117-
}
118-
fragment FriendsAppearsIn on Character {
119-
friends @stream(label: "appearsInLabel", initial_count: 2) {
120-
appearsIn
149+
fragment FriendsAppearsIn on Character {
150+
friends @stream(label: "appearsInLabel", initial_count: 2) {
151+
appearsIn
152+
}
121153
}
122-
}
123-
`;
124-
const result = await graphql(StarWarsSchemaDeferStreamEnabled, query);
125-
const { patches: patchesIterable, ...initial } = result;
126-
expect(initial).to.deep.equal({
127-
data: {
128-
hero: {
129-
friends: [
130-
{
131-
id: '1000',
132-
appearsIn: ['NEW_HOPE', 'EMPIRE', 'JEDI'],
133-
name: 'Luke Skywalker',
134-
},
135-
{
136-
id: '1002',
137-
appearsIn: ['NEW_HOPE', 'EMPIRE', 'JEDI'],
138-
},
139-
{
140-
id: '1003',
141-
},
142-
],
154+
`;
155+
const result = await graphql(StarWarsSchemaDeferStreamEnabled, query);
156+
const { patches: patchesIterable, ...initial } = result;
157+
expect(initial).to.deep.equal({
158+
data: {
159+
hero: {
160+
friends: [
161+
{
162+
id: '1000',
163+
appearsIn: ['NEW_HOPE', 'EMPIRE', 'JEDI'],
164+
name: 'Luke Skywalker',
165+
},
166+
{
167+
id: '1002',
168+
appearsIn: ['NEW_HOPE', 'EMPIRE', 'JEDI'],
169+
},
170+
{
171+
id: '1003',
172+
},
173+
],
174+
},
143175
},
144-
},
145-
});
176+
});
146177

147-
const patches = [];
178+
const patches = [];
148179

149-
if (patchesIterable) {
150-
await forAwaitEach(patchesIterable, patch => {
151-
patches.push(patch);
152-
});
153-
}
180+
if (patchesIterable) {
181+
await forAwaitEach(patchesIterable, patch => {
182+
patches.push(patch);
183+
});
184+
}
154185

155-
expect(patches).to.have.lengthOf(3);
156-
expect(patches[0]).to.deep.equal({
157-
data: {
158-
name: 'Han Solo',
159-
},
160-
path: ['hero', 'friends', 1],
161-
label: 'nameLabel',
162-
});
186+
expect(patches).to.have.lengthOf(3);
187+
expect(patches[0]).to.deep.equal({
188+
data: {
189+
name: 'Han Solo',
190+
},
191+
path: ['hero', 'friends', 1],
192+
label: 'nameLabel',
193+
});
163194

164-
expect(patches[1]).to.deep.equal({
165-
data: {
166-
name: 'Leia Organa',
167-
},
168-
path: ['hero', 'friends', 2],
169-
label: 'nameLabel',
170-
});
195+
expect(patches[1]).to.deep.equal({
196+
data: {
197+
name: 'Leia Organa',
198+
},
199+
path: ['hero', 'friends', 2],
200+
label: 'nameLabel',
201+
});
171202

172-
expect(patches[2]).to.deep.equal({
173-
data: {
174-
appearsIn: ['NEW_HOPE', 'EMPIRE', 'JEDI'],
175-
},
176-
path: ['hero', 'friends', 2],
177-
label: 'appearsInLabel',
203+
expect(patches[2]).to.deep.equal({
204+
data: {
205+
appearsIn: ['NEW_HOPE', 'EMPIRE', 'JEDI'],
206+
},
207+
path: ['hero', 'friends', 2],
208+
label: 'appearsInLabel',
209+
});
178210
});
179211
});
180212
});

0 commit comments

Comments
 (0)