Skip to content

Commit d9f959e

Browse files
starWarsIntrospection-test: cleanup + add explanation comment (#2085)
1 parent cd9fc8e commit d9f959e

File tree

1 file changed

+84
-134
lines changed

1 file changed

+84
-134
lines changed

src/__tests__/starWarsIntrospection-test.js

Lines changed: 84 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -7,152 +7,126 @@ import { graphqlSync } from '../graphql';
77

88
import { StarWarsSchema } from './starWarsSchema';
99

10+
function queryStarWars(source) {
11+
const result = graphqlSync({ schema: StarWarsSchema, source });
12+
expect(Object.keys(result)).to.deep.equal(['data']);
13+
return result.data;
14+
}
15+
1016
describe('Star Wars Introspection Tests', () => {
1117
describe('Basic Introspection', () => {
1218
it('Allows querying the schema for types', () => {
13-
const query = `
14-
query IntrospectionTypeQuery {
19+
const data = queryStarWars(`
20+
{
1521
__schema {
1622
types {
1723
name
1824
}
1925
}
2026
}
21-
`;
22-
const expected = {
27+
`);
28+
29+
// Include all types used by StarWars schema, introspection types and
30+
// standard directives. For example, `Boolean` is used in `@skip`,
31+
// `@include` and also inside introspection types.
32+
expect(data).to.deep.equal({
2333
__schema: {
2434
types: [
25-
{
26-
name: 'Query',
27-
},
28-
{
29-
name: 'Episode',
30-
},
31-
{
32-
name: 'Character',
33-
},
34-
{
35-
name: 'String',
36-
},
37-
{
38-
name: 'Human',
39-
},
40-
{
41-
name: 'Droid',
42-
},
43-
{
44-
name: '__Schema',
45-
},
46-
{
47-
name: '__Type',
48-
},
49-
{
50-
name: '__TypeKind',
51-
},
52-
{
53-
name: 'Boolean',
54-
},
55-
{
56-
name: '__Field',
57-
},
58-
{
59-
name: '__InputValue',
60-
},
61-
{
62-
name: '__EnumValue',
63-
},
64-
{
65-
name: '__Directive',
66-
},
67-
{
68-
name: '__DirectiveLocation',
69-
},
35+
{ name: 'Query' },
36+
{ name: 'Episode' },
37+
{ name: 'Character' },
38+
{ name: 'String' },
39+
{ name: 'Human' },
40+
{ name: 'Droid' },
41+
{ name: '__Schema' },
42+
{ name: '__Type' },
43+
{ name: '__TypeKind' },
44+
{ name: 'Boolean' },
45+
{ name: '__Field' },
46+
{ name: '__InputValue' },
47+
{ name: '__EnumValue' },
48+
{ name: '__Directive' },
49+
{ name: '__DirectiveLocation' },
7050
],
7151
},
72-
};
73-
const result = graphqlSync(StarWarsSchema, query);
74-
expect(result).to.deep.equal({ data: expected });
52+
});
7553
});
7654

7755
it('Allows querying the schema for query type', () => {
78-
const query = `
79-
query IntrospectionQueryTypeQuery {
56+
const data = queryStarWars(`
57+
{
8058
__schema {
8159
queryType {
8260
name
8361
}
8462
}
8563
}
86-
`;
87-
const expected = {
64+
`);
65+
66+
expect(data).to.deep.equal({
8867
__schema: {
8968
queryType: {
9069
name: 'Query',
9170
},
9271
},
93-
};
94-
const result = graphqlSync(StarWarsSchema, query);
95-
expect(result).to.deep.equal({ data: expected });
72+
});
9673
});
9774

9875
it('Allows querying the schema for a specific type', () => {
99-
const query = `
100-
query IntrospectionDroidTypeQuery {
76+
const data = queryStarWars(`
77+
{
10178
__type(name: "Droid") {
10279
name
10380
}
10481
}
105-
`;
106-
const expected = {
82+
`);
83+
84+
expect(data).to.deep.equal({
10785
__type: {
10886
name: 'Droid',
10987
},
110-
};
111-
const result = graphqlSync(StarWarsSchema, query);
112-
expect(result).to.deep.equal({ data: expected });
88+
});
11389
});
11490

11591
it('Allows querying the schema for an object kind', () => {
116-
const query = `
117-
query IntrospectionDroidKindQuery {
92+
const data = queryStarWars(`
93+
{
11894
__type(name: "Droid") {
11995
name
12096
kind
12197
}
12298
}
123-
`;
124-
const expected = {
99+
`);
100+
101+
expect(data).to.deep.equal({
125102
__type: {
126103
name: 'Droid',
127104
kind: 'OBJECT',
128105
},
129-
};
130-
const result = graphqlSync(StarWarsSchema, query);
131-
expect(result).to.deep.equal({ data: expected });
106+
});
132107
});
133108

134109
it('Allows querying the schema for an interface kind', () => {
135-
const query = `
136-
query IntrospectionCharacterKindQuery {
110+
const data = queryStarWars(`
111+
{
137112
__type(name: "Character") {
138113
name
139114
kind
140115
}
141116
}
142-
`;
143-
const expected = {
117+
`);
118+
119+
expect(data).to.deep.equal({
144120
__type: {
145121
name: 'Character',
146122
kind: 'INTERFACE',
147123
},
148-
};
149-
const result = graphqlSync(StarWarsSchema, query);
150-
expect(result).to.deep.equal({ data: expected });
124+
});
151125
});
152126

153127
it('Allows querying the schema for object fields', () => {
154-
const query = `
155-
query IntrospectionDroidFieldsQuery {
128+
const data = queryStarWars(`
129+
{
156130
__type(name: "Droid") {
157131
name
158132
fields {
@@ -164,64 +138,44 @@ describe('Star Wars Introspection Tests', () => {
164138
}
165139
}
166140
}
167-
`;
168-
const expected = {
141+
`);
142+
143+
expect(data).to.deep.equal({
169144
__type: {
170145
name: 'Droid',
171146
fields: [
172147
{
173148
name: 'id',
174-
type: {
175-
name: null,
176-
kind: 'NON_NULL',
177-
},
149+
type: { name: null, kind: 'NON_NULL' },
178150
},
179151
{
180152
name: 'name',
181-
type: {
182-
name: 'String',
183-
kind: 'SCALAR',
184-
},
153+
type: { name: 'String', kind: 'SCALAR' },
185154
},
186155
{
187156
name: 'friends',
188-
type: {
189-
name: null,
190-
kind: 'LIST',
191-
},
157+
type: { name: null, kind: 'LIST' },
192158
},
193159
{
194160
name: 'appearsIn',
195-
type: {
196-
name: null,
197-
kind: 'LIST',
198-
},
161+
type: { name: null, kind: 'LIST' },
199162
},
200163
{
201164
name: 'secretBackstory',
202-
type: {
203-
name: 'String',
204-
kind: 'SCALAR',
205-
},
165+
type: { name: 'String', kind: 'SCALAR' },
206166
},
207167
{
208168
name: 'primaryFunction',
209-
type: {
210-
name: 'String',
211-
kind: 'SCALAR',
212-
},
169+
type: { name: 'String', kind: 'SCALAR' },
213170
},
214171
],
215172
},
216-
};
217-
218-
const result = graphqlSync(StarWarsSchema, query);
219-
expect(result).to.deep.equal({ data: expected });
173+
});
220174
});
221175

222176
it('Allows querying the schema for nested object fields', () => {
223-
const query = `
224-
query IntrospectionDroidNestedFieldsQuery {
177+
const data = queryStarWars(`
178+
{
225179
__type(name: "Droid") {
226180
name
227181
fields {
@@ -237,8 +191,9 @@ describe('Star Wars Introspection Tests', () => {
237191
}
238192
}
239193
}
240-
`;
241-
const expected = {
194+
`);
195+
196+
expect(data).to.deep.equal({
242197
__type: {
243198
name: 'Droid',
244199
fields: [
@@ -301,14 +256,12 @@ describe('Star Wars Introspection Tests', () => {
301256
},
302257
],
303258
},
304-
};
305-
const result = graphqlSync(StarWarsSchema, query);
306-
expect(result).to.deep.equal({ data: expected });
259+
});
307260
});
308261

309262
it('Allows querying the schema for field args', () => {
310-
const query = `
311-
query IntrospectionQueryTypeQuery {
263+
const data = queryStarWars(`
264+
{
312265
__schema {
313266
queryType {
314267
fields {
@@ -330,8 +283,9 @@ describe('Star Wars Introspection Tests', () => {
330283
}
331284
}
332285
}
333-
`;
334-
const expected = {
286+
`);
287+
288+
expect(data).to.deep.equal({
335289
__schema: {
336290
queryType: {
337291
fields: [
@@ -390,29 +344,25 @@ describe('Star Wars Introspection Tests', () => {
390344
],
391345
},
392346
},
393-
};
394-
395-
const result = graphqlSync(StarWarsSchema, query);
396-
expect(result).to.deep.equal({ data: expected });
347+
});
397348
});
398349

399350
it('Allows querying the schema for documentation', () => {
400-
const query = `
401-
query IntrospectionDroidDescriptionQuery {
351+
const data = queryStarWars(`
352+
{
402353
__type(name: "Droid") {
403354
name
404355
description
405356
}
406357
}
407-
`;
408-
const expected = {
358+
`);
359+
360+
expect(data).to.deep.equal({
409361
__type: {
410362
name: 'Droid',
411363
description: 'A mechanical creature in the Star Wars universe.',
412364
},
413-
};
414-
const result = graphqlSync(StarWarsSchema, query);
415-
expect(result).to.deep.equal({ data: expected });
365+
});
416366
});
417367
});
418368
});

0 commit comments

Comments
 (0)