Skip to content

Commit a7bf614

Browse files
committed
works
1 parent a075add commit a7bf614

File tree

5 files changed

+71
-73
lines changed

5 files changed

+71
-73
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"parser": "babel-eslint",
33
"arrowFunctions": true,
4+
"asyncFunctions": true,
5+
"es7.asyncFunctions": true,
46
"blockBindings": true,
57
"classes": true,
68
"defaultParams": true,
@@ -13,6 +15,7 @@
1315
"objectLiteralShorthandProperties": true,
1416
"spread": true,
1517
"templateStrings": true,
18+
"experimental" : true,
1619
"env": {
1720
"node": true,
1821
"es6": true

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"lint": "eslint src",
3737
"check": "flow check",
3838
"cover": "babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
39-
"build": "rm -rf lib/* && babel src --ignore __tests__ --optional runtime --out-dir lib",
40-
"watch": "babel --optional runtime scripts/watch.js | node",
39+
"build": "rm -rf lib/* && babel src --ignore __tests__ --optional runtime,es7.asyncFunctions --out-dir lib",
40+
"watch": "babel --optional runtime,es7.asyncFunctions scripts/watch.js | node",
4141
"coveralls": "babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha --report lcovonly -- $npm_package_options_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
4242
},
4343
"dependencies": {

scripts/mocha-bootload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
require('babel/register')({
11-
optional: ['runtime']
11+
optional: ['runtime', 'es7.asyncFunctions']
1212
});
1313

1414
var chai = require('chai');

src/__tests__/starWarsIntrospectionTests.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,9 @@ import { graphql } from '../graphql';
1515
// 80+ char lines are useful in describe/it, so ignore in this file.
1616
/*eslint-disable max-len */
1717

18-
/**
19-
* Helper function to test a query and the expected response.
20-
*/
21-
function testQuery(query, expected) {
22-
return expect(
23-
graphql(StarWarsSchema, query)
24-
).to.become({data: expected});
25-
}
26-
27-
2818
describe('Star Wars Introspection Tests', () => {
2919
describe('Basic Introspection', () => {
30-
it('Allows querying the schema for types', () => {
20+
it('Allows querying the schema for types', async () => {
3121
var query = `
3222
query IntrospectionTypeQuery {
3323
__schema {
@@ -85,10 +75,11 @@ describe('Star Wars Introspection Tests', () => {
8575
]
8676
}
8777
};
88-
return testQuery(query, expected);
78+
var result = await graphql(StarWarsSchema, query);
79+
expect(result).to.deep.equal({ data: expected });
8980
});
9081

91-
it('Allows querying the schema for query type', () => {
82+
it('Allows querying the schema for query type', async () => {
9283
var query = `
9384
query IntrospectionQueryTypeQuery {
9485
__schema {
@@ -105,10 +96,11 @@ describe('Star Wars Introspection Tests', () => {
10596
},
10697
}
10798
};
108-
return testQuery(query, expected);
99+
var result = await graphql(StarWarsSchema, query);
100+
expect(result).to.deep.equal({ data: expected });
109101
});
110102

111-
it('Allows querying the schema for a specific type', () => {
103+
it('Allows querying the schema for a specific type', async () => {
112104
var query = `
113105
query IntrospectionDroidTypeQuery {
114106
__type(name: "Droid") {
@@ -121,10 +113,11 @@ describe('Star Wars Introspection Tests', () => {
121113
name: 'Droid'
122114
}
123115
};
124-
return testQuery(query, expected);
116+
var result = await graphql(StarWarsSchema, query);
117+
expect(result).to.deep.equal({ data: expected });
125118
});
126119

127-
it('Allows querying the schema for an object kind', () => {
120+
it('Allows querying the schema for an object kind', async () => {
128121
var query = `
129122
query IntrospectionDroidKindQuery {
130123
__type(name: "Droid") {
@@ -139,10 +132,11 @@ describe('Star Wars Introspection Tests', () => {
139132
kind: 'OBJECT'
140133
}
141134
};
142-
return testQuery(query, expected);
135+
var result = await graphql(StarWarsSchema, query);
136+
expect(result).to.deep.equal({ data: expected });
143137
});
144138

145-
it('Allows querying the schema for an interface kind', () => {
139+
it('Allows querying the schema for an interface kind', async () => {
146140
var query = `
147141
query IntrospectionCharacterKindQuery {
148142
__type(name: "Character") {
@@ -157,10 +151,11 @@ describe('Star Wars Introspection Tests', () => {
157151
kind: 'INTERFACE'
158152
}
159153
};
160-
return testQuery(query, expected);
154+
var result = await graphql(StarWarsSchema, query);
155+
expect(result).to.deep.equal({ data: expected });
161156
});
162157

163-
it('Allows querying the schema for object fields', () => {
158+
it('Allows querying the schema for object fields', async () => {
164159
var query = `
165160
query IntrospectionDroidFieldsQuery {
166161
__type(name: "Droid") {
@@ -217,10 +212,12 @@ describe('Star Wars Introspection Tests', () => {
217212
]
218213
}
219214
};
220-
return testQuery(query, expected);
215+
216+
var result = await graphql(StarWarsSchema, query);
217+
expect(result).to.deep.equal({ data: expected });
221218
});
222219

223-
it('Allows querying the schema for nested object fields', () => {
220+
it('Allows querying the schema for nested object fields', async () => {
224221
var query = `
225222
query IntrospectionDroidNestedFieldsQuery {
226223
__type(name: "Droid") {
@@ -295,10 +292,11 @@ describe('Star Wars Introspection Tests', () => {
295292
]
296293
}
297294
};
298-
return testQuery(query, expected);
295+
var result = await graphql(StarWarsSchema, query);
296+
expect(result).to.deep.equal({ data: expected });
299297
});
300298

301-
it('Allows querying the schema for field args', () => {
299+
it('Allows querying the schema for field args', async () => {
302300
var query = `
303301
query IntrospectionQueryTypeQuery {
304302
__schema {
@@ -372,10 +370,12 @@ describe('Star Wars Introspection Tests', () => {
372370
}
373371
};
374372

375-
return testQuery(query, expected);
373+
374+
var result = await graphql(StarWarsSchema, query);
375+
expect(result).to.deep.equal({ data: expected });
376376
});
377377

378-
it('Allows querying the schema for documentation', () => {
378+
it('Allows querying the schema for documentation', async () => {
379379
var query = `
380380
query IntrospectionDroidDescriptionQuery {
381381
__type(name: "Droid") {
@@ -390,7 +390,8 @@ describe('Star Wars Introspection Tests', () => {
390390
description: 'A mechanical creature in the Star Wars universe.'
391391
}
392392
};
393-
return testQuery(query, expected);
393+
var result = await graphql(StarWarsSchema, query);
394+
expect(result).to.deep.equal({ data: expected });
394395
});
395396
});
396397
});

src/__tests__/starWarsQueryTests.js

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,9 @@ import { graphql } from '../graphql';
1515
// 80+ char lines are useful in describe/it, so ignore in this file.
1616
/*eslint-disable max-len */
1717

18-
/**
19-
* Helper function to test a query and the expected response.
20-
*/
21-
function testQuery(query, expected) {
22-
return expect(
23-
graphql(StarWarsSchema, query)
24-
).to.become({data: expected});
25-
}
26-
27-
/**
28-
* Helper function to test a query with params and the expected response.
29-
*/
30-
function testQueryWithParams(query, params, expected) {
31-
return expect(
32-
graphql(StarWarsSchema, query, null, params)
33-
).to.become({data: expected});
34-
}
35-
3618
describe('Star Wars Query Tests', () => {
3719
describe('Basic Queries', () => {
38-
it('Correctly identifies R2-D2 as the hero of the Star Wars Saga', () => {
20+
it('Correctly identifies R2-D2 as the hero of the Star Wars Saga', async () => {
3921
var query = `
4022
query HeroNameQuery {
4123
hero {
@@ -48,10 +30,11 @@ describe('Star Wars Query Tests', () => {
4830
name: 'R2-D2'
4931
}
5032
};
51-
return testQuery(query, expected);
33+
var result = await graphql(StarWarsSchema, query);
34+
expect(result).to.deep.equal({ data: expected });
5235
});
5336

54-
it('Allows us to query for the ID and friends of R2-D2', () => {
37+
it('Allows us to query for the ID and friends of R2-D2', async () => {
5538
var query = `
5639
query HeroNameAndFriendsQuery {
5740
hero {
@@ -80,12 +63,13 @@ describe('Star Wars Query Tests', () => {
8063
]
8164
}
8265
};
83-
return testQuery(query, expected);
66+
var result = await graphql(StarWarsSchema, query);
67+
expect(result).to.deep.equal({ data: expected });
8468
});
8569
});
8670

8771
describe('Nested Queries', () => {
88-
it('Allows us to query for the friends of friends of R2-D2', () => {
72+
it('Allows us to query for the friends of friends of R2-D2', async () => {
8973
var query = `
9074
query NestedQuery {
9175
hero {
@@ -158,12 +142,13 @@ describe('Star Wars Query Tests', () => {
158142
]
159143
}
160144
};
161-
return testQuery(query, expected);
145+
var result = await graphql(StarWarsSchema, query);
146+
expect(result).to.deep.equal({ data: expected });
162147
});
163148
});
164149

165150
describe('Using IDs and query parameters to refetch objects', () => {
166-
it('Allows us to query for Luke Skywalker directly, using his ID', () => {
151+
it('Allows us to query for Luke Skywalker directly, using his ID', async () => {
167152
var query = `
168153
query FetchLukeQuery {
169154
human(id: "1000") {
@@ -176,10 +161,11 @@ describe('Star Wars Query Tests', () => {
176161
name: 'Luke Skywalker'
177162
}
178163
};
179-
return testQuery(query, expected);
164+
var result = await graphql(StarWarsSchema, query);
165+
expect(result).to.deep.equal({ data: expected });
180166
});
181167

182-
it('Allows us to create a generic query, then use it to fetch Luke Skywalker using his ID', () => {
168+
it('Allows us to create a generic query, then use it to fetch Luke Skywalker using his ID', async () => {
183169
var query = `
184170
query FetchSomeIDQuery($someId: String!) {
185171
human(id: $someId) {
@@ -195,10 +181,11 @@ describe('Star Wars Query Tests', () => {
195181
name: 'Luke Skywalker'
196182
}
197183
};
198-
return testQueryWithParams(query, params, expected);
184+
var result = await graphql(StarWarsSchema, query, null, params);
185+
expect(result).to.deep.equal({ data: expected });
199186
});
200187

201-
it('Allows us to create a generic query, then use it to fetch Han Solo using his ID', () => {
188+
it('Allows us to create a generic query, then use it to fetch Han Solo using his ID', async () => {
202189
var query = `
203190
query FetchSomeIDQuery($someId: String!) {
204191
human(id: $someId) {
@@ -214,10 +201,11 @@ describe('Star Wars Query Tests', () => {
214201
name: 'Han Solo'
215202
}
216203
};
217-
return testQueryWithParams(query, params, expected);
204+
var result = await graphql(StarWarsSchema, query, null, params);
205+
expect(result).to.deep.equal({ data: expected });
218206
});
219207

220-
it('Allows us to create a generic query, then pass an invalid ID to get null back', () => {
208+
it('Allows us to create a generic query, then pass an invalid ID to get null back', async () => {
221209
var query = `
222210
query humanQuery($id: String!) {
223211
human(id: $id) {
@@ -231,12 +219,13 @@ describe('Star Wars Query Tests', () => {
231219
var expected = {
232220
human: null
233221
};
234-
return testQueryWithParams(query, params, expected);
222+
var result = await graphql(StarWarsSchema, query, null, params);
223+
expect(result).to.deep.equal({ data: expected });
235224
});
236225
});
237226

238227
describe('Using aliases to change the key in the response', () => {
239-
it('Allows us to query for Luke, changing his key with an alias', () => {
228+
it('Allows us to query for Luke, changing his key with an alias', async () => {
240229
var query = `
241230
query FetchLukeAliased {
242231
luke: human(id: "1000") {
@@ -249,10 +238,11 @@ describe('Star Wars Query Tests', () => {
249238
name: 'Luke Skywalker'
250239
},
251240
};
252-
return testQuery(query, expected);
241+
var result = await graphql(StarWarsSchema, query);
242+
expect(result).to.deep.equal({ data: expected });
253243
});
254244

255-
it('Allows us to query for both Luke and Leia, using two root fields and an alias', () => {
245+
it('Allows us to query for both Luke and Leia, using two root fields and an alias', async () => {
256246
var query = `
257247
query FetchLukeAndLeiaAliased {
258248
luke: human(id: "1000") {
@@ -271,12 +261,13 @@ describe('Star Wars Query Tests', () => {
271261
name: 'Leia Organa'
272262
}
273263
};
274-
return testQuery(query, expected);
264+
var result = await graphql(StarWarsSchema, query);
265+
expect(result).to.deep.equal({ data: expected });
275266
});
276267
});
277268

278269
describe('Uses fragments to express more complex queries', () => {
279-
it('Allows us to query using duplicated content', () => {
270+
it('Allows us to query using duplicated content', async() => {
280271
var query = `
281272
query DuplicateFields {
282273
luke: human(id: "1000") {
@@ -299,10 +290,11 @@ describe('Star Wars Query Tests', () => {
299290
homePlanet: 'Alderaan'
300291
}
301292
};
302-
return testQuery(query, expected);
293+
var result = await graphql(StarWarsSchema, query);
294+
expect(result).to.deep.equal({ data: expected });
303295
});
304296

305-
it('Allows us to use a fragment to avoid duplicating content', () => {
297+
it('Allows us to use a fragment to avoid duplicating content', async () => {
306298
var query = `
307299
query UseFragment {
308300
luke: human(id: "1000") {
@@ -328,12 +320,13 @@ describe('Star Wars Query Tests', () => {
328320
homePlanet: 'Alderaan'
329321
}
330322
};
331-
return testQuery(query, expected);
323+
var result = await graphql(StarWarsSchema, query);
324+
expect(result).to.deep.equal({ data: expected });
332325
});
333326
});
334327

335328
describe('Using __typename to find the type of an object', () => {
336-
it('Allows us to verify that R2-D2 is a droid', () => {
329+
it('Allows us to verify that R2-D2 is a droid', async () => {
337330
var query = `
338331
query CheckTypeOfR2 {
339332
hero {
@@ -348,7 +341,8 @@ describe('Star Wars Query Tests', () => {
348341
name: 'R2-D2'
349342
},
350343
};
351-
return testQuery(query, expected);
344+
var result = await graphql(StarWarsSchema, query);
345+
expect(result).to.deep.equal({ data: expected });
352346
});
353347
});
354348
});

0 commit comments

Comments
 (0)