Skip to content

Commit db5c587

Browse files
tests: Switch to using named args for graphql/graphqlSync (#312)
1 parent 6983c14 commit db5c587

File tree

9 files changed

+116
-142
lines changed

9 files changed

+116
-142
lines changed

src/__tests__/starWarsConnectionTests.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33
import { graphqlSync } from 'graphql';
44

5-
import { StarWarsSchema } from './starWarsSchema';
5+
import { StarWarsSchema as schema } from './starWarsSchema';
66

77
describe('Star Wars connections', () => {
88
it('fetches the first ship of the rebels', () => {
9-
const query = `
9+
const source = `
1010
query RebelsShipsQuery {
1111
rebels {
1212
name,
@@ -21,7 +21,7 @@ describe('Star Wars connections', () => {
2121
}
2222
`;
2323

24-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
24+
expect(graphqlSync({ schema, source })).to.deep.equal({
2525
data: {
2626
rebels: {
2727
name: 'Alliance to Restore the Republic',
@@ -38,7 +38,7 @@ describe('Star Wars connections', () => {
3838
});
3939

4040
it('fetches the first two ships of the rebels with a cursor', () => {
41-
const query = `
41+
const source = `
4242
query MoreRebelShipsQuery {
4343
rebels {
4444
name,
@@ -54,7 +54,7 @@ describe('Star Wars connections', () => {
5454
}
5555
`;
5656

57-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
57+
expect(graphqlSync({ schema, source })).to.deep.equal({
5858
data: {
5959
rebels: {
6060
name: 'Alliance to Restore the Republic',
@@ -76,7 +76,7 @@ describe('Star Wars connections', () => {
7676
});
7777

7878
it('fetches the next three ships of the rebels with a cursor', () => {
79-
const query = `
79+
const source = `
8080
query EndOfRebelShipsQuery {
8181
rebels {
8282
name,
@@ -92,7 +92,7 @@ describe('Star Wars connections', () => {
9292
}
9393
`;
9494

95-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
95+
expect(graphqlSync({ schema, source })).to.deep.equal({
9696
data: {
9797
rebels: {
9898
name: 'Alliance to Restore the Republic',
@@ -118,7 +118,7 @@ describe('Star Wars connections', () => {
118118
});
119119

120120
it('fetches no ships of the rebels at the end of connection', () => {
121-
const query = `
121+
const source = `
122122
query RebelsQuery {
123123
rebels {
124124
name,
@@ -134,7 +134,7 @@ describe('Star Wars connections', () => {
134134
}
135135
`;
136136

137-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
137+
expect(graphqlSync({ schema, source })).to.deep.equal({
138138
data: {
139139
rebels: {
140140
name: 'Alliance to Restore the Republic',
@@ -147,7 +147,7 @@ describe('Star Wars connections', () => {
147147
});
148148

149149
it('identifies the end of the list', () => {
150-
const query = `
150+
const source = `
151151
query EndOfRebelShipsQuery {
152152
rebels {
153153
name,
@@ -175,7 +175,7 @@ describe('Star Wars connections', () => {
175175
}
176176
`;
177177

178-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
178+
expect(graphqlSync({ schema, source })).to.deep.equal({
179179
data: {
180180
rebels: {
181181
name: 'Alliance to Restore the Republic',

src/__tests__/starWarsMutationTests.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33
import { graphqlSync } from 'graphql';
44

5-
import { StarWarsSchema } from './starWarsSchema';
5+
import { StarWarsSchema as schema } from './starWarsSchema';
66

77
describe('Star Wars mutations', () => {
88
it('mutates the data set', () => {
9-
const mutation = `
9+
const source = `
1010
mutation AddBWingQuery($input: IntroduceShipInput!) {
1111
introduceShip(input: $input) {
1212
ship {
@@ -20,26 +20,28 @@ describe('Star Wars mutations', () => {
2020
}
2121
}
2222
`;
23-
const params = {
23+
const variableValues = {
2424
input: {
2525
shipName: 'B-Wing',
2626
factionId: '1',
2727
clientMutationId: 'abcde',
2828
},
2929
};
30-
const expected = {
31-
introduceShip: {
32-
ship: {
33-
id: 'U2hpcDo5',
34-
name: 'B-Wing',
35-
},
36-
faction: {
37-
name: 'Alliance to Restore the Republic',
30+
31+
const result = graphqlSync({ schema, source, variableValues });
32+
expect(result).to.deep.equal({
33+
data: {
34+
introduceShip: {
35+
ship: {
36+
id: 'U2hpcDo5',
37+
name: 'B-Wing',
38+
},
39+
faction: {
40+
name: 'Alliance to Restore the Republic',
41+
},
42+
clientMutationId: 'abcde',
3843
},
39-
clientMutationId: 'abcde',
4044
},
41-
};
42-
const result = graphqlSync(StarWarsSchema, mutation, null, null, params);
43-
expect(result).to.deep.equal({ data: expected });
45+
});
4446
});
4547
});

src/__tests__/starWarsObjectIdentificationTests.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33
import { graphqlSync } from 'graphql';
44

5-
import { StarWarsSchema } from './starWarsSchema';
5+
import { StarWarsSchema as schema } from './starWarsSchema';
66

77
describe('Star Wars object identification', () => {
88
it('fetches the ID and name of the rebels', () => {
9-
const query = `
9+
const source = `
1010
query RebelsQuery {
1111
rebels {
1212
id
@@ -15,7 +15,7 @@ describe('Star Wars object identification', () => {
1515
}
1616
`;
1717

18-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
18+
expect(graphqlSync({ schema, source })).to.deep.equal({
1919
data: {
2020
rebels: {
2121
id: 'RmFjdGlvbjox',
@@ -26,7 +26,7 @@ describe('Star Wars object identification', () => {
2626
});
2727

2828
it('refetches the rebels', () => {
29-
const query = `
29+
const source = `
3030
query RebelsRefetchQuery {
3131
node(id: "RmFjdGlvbjox") {
3232
id
@@ -37,7 +37,7 @@ describe('Star Wars object identification', () => {
3737
}
3838
`;
3939

40-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
40+
expect(graphqlSync({ schema, source })).to.deep.equal({
4141
data: {
4242
node: {
4343
id: 'RmFjdGlvbjox',
@@ -48,7 +48,7 @@ describe('Star Wars object identification', () => {
4848
});
4949

5050
it('fetches the ID and name of the empire', () => {
51-
const query = `
51+
const source = `
5252
query EmpireQuery {
5353
empire {
5454
id
@@ -57,18 +57,15 @@ describe('Star Wars object identification', () => {
5757
}
5858
`;
5959

60-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
60+
expect(graphqlSync({ schema, source })).to.deep.equal({
6161
data: {
62-
empire: {
63-
id: 'RmFjdGlvbjoy',
64-
name: 'Galactic Empire',
65-
},
62+
empire: { id: 'RmFjdGlvbjoy', name: 'Galactic Empire' },
6663
},
6764
});
6865
});
6966

7067
it('refetches the empire', () => {
71-
const query = `
68+
const source = `
7269
query EmpireRefetchQuery {
7370
node(id: "RmFjdGlvbjoy") {
7471
id
@@ -79,18 +76,15 @@ describe('Star Wars object identification', () => {
7976
}
8077
`;
8178

82-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
79+
expect(graphqlSync({ schema, source })).to.deep.equal({
8380
data: {
84-
node: {
85-
id: 'RmFjdGlvbjoy',
86-
name: 'Galactic Empire',
87-
},
81+
node: { id: 'RmFjdGlvbjoy', name: 'Galactic Empire' },
8882
},
8983
});
9084
});
9185

9286
it('refetches the X-Wing', () => {
93-
const query = `
87+
const source = `
9488
query XWingRefetchQuery {
9589
node(id: "U2hpcDox") {
9690
id
@@ -101,12 +95,9 @@ describe('Star Wars object identification', () => {
10195
}
10296
`;
10397

104-
expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
98+
expect(graphqlSync({ schema, source })).to.deep.equal({
10599
data: {
106-
node: {
107-
id: 'U2hpcDox',
108-
name: 'X-Wing',
109-
},
100+
node: { id: 'U2hpcDox', name: 'X-Wing' },
110101
},
111102
});
112103
});

src/connection/__tests__/connection.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const schema = new GraphQLSchema({
8888

8989
describe('connectionDefinition()', () => {
9090
it('includes connection and edge fields', () => {
91-
const query = `
91+
const source = `
9292
query FriendsQuery {
9393
user {
9494
friends(first: 2) {
@@ -104,7 +104,7 @@ describe('connectionDefinition()', () => {
104104
}
105105
`;
106106

107-
expect(graphqlSync(schema, query)).to.deep.equal({
107+
expect(graphqlSync({ schema, source })).to.deep.equal({
108108
data: {
109109
user: {
110110
friends: {
@@ -126,7 +126,7 @@ describe('connectionDefinition()', () => {
126126
});
127127

128128
it('works with forwardConnectionArgs', () => {
129-
const query = `
129+
const source = `
130130
query FriendsQuery {
131131
user {
132132
friendsForward(first: 2) {
@@ -140,26 +140,19 @@ describe('connectionDefinition()', () => {
140140
}
141141
`;
142142

143-
expect(graphqlSync(schema, query)).to.deep.equal({
143+
expect(graphqlSync({ schema, source })).to.deep.equal({
144144
data: {
145145
user: {
146146
friendsForward: {
147-
edges: [
148-
{
149-
node: { name: 'Nick' },
150-
},
151-
{
152-
node: { name: 'Lee' },
153-
},
154-
],
147+
edges: [{ node: { name: 'Nick' } }, { node: { name: 'Lee' } }],
155148
},
156149
},
157150
},
158151
});
159152
});
160153

161154
it('works with backwardConnectionArgs', () => {
162-
const query = `
155+
const source = `
163156
query FriendsQuery {
164157
user {
165158
friendsBackward(last: 2) {
@@ -173,18 +166,11 @@ describe('connectionDefinition()', () => {
173166
}
174167
`;
175168

176-
expect(graphqlSync(schema, query)).to.deep.equal({
169+
expect(graphqlSync({ schema, source })).to.deep.equal({
177170
data: {
178171
user: {
179172
friendsBackward: {
180-
edges: [
181-
{
182-
node: { name: 'Joe' },
183-
},
184-
{
185-
node: { name: 'Tim' },
186-
},
187-
],
173+
edges: [{ node: { name: 'Joe' } }, { node: { name: 'Tim' } }],
188174
},
189175
},
190176
},

0 commit comments

Comments
 (0)