Skip to content

Commit 8c9caf1

Browse files
committed
Split out tests for Enum and Variable types
1 parent b1c4eb7 commit 8c9caf1

File tree

6 files changed

+82
-66
lines changed

6 files changed

+82
-66
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ query {
200200

201201
## TO-DO List
202202

203-
* Fragments
203+
* Support Named Queries / Mutations
204204
* Probably some other things!...
205205

206206
Pull requests welcome!

src/__tests__/jsonToGraphQLQuery.tests.ts

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { expect } from 'chai';
3-
import { jsonToGraphQLQuery, EnumType, VariableType } from '../';
3+
import { jsonToGraphQLQuery } from '../';
44

55
describe('jsonToGraphQL()', () => {
66

@@ -66,29 +66,6 @@ describe('jsonToGraphQL()', () => {
6666
}`);
6767
});
6868

69-
it('converts a query with enum arguments', () => {
70-
const query = {
71-
query: {
72-
Posts: {
73-
__args: {
74-
status: new EnumType('PUBLISHED')
75-
},
76-
id: true,
77-
title: true,
78-
post_date: true
79-
}
80-
}
81-
};
82-
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
83-
`query {
84-
Posts (status: PUBLISHED) {
85-
id
86-
title
87-
post_date
88-
}
89-
}`);
90-
});
91-
9269
it('converts a query with JSON arguments', () => {
9370
const query = {
9471
query: {
@@ -305,41 +282,3 @@ describe('jsonToGraphQL()', () => {
305282
);
306283
});
307284
});
308-
309-
it('converts a query variables', () => {
310-
const query = {
311-
query: {
312-
__variables: {
313-
variableName: 'String!'
314-
},
315-
Posts: {
316-
__args: {
317-
arg1: 20,
318-
arg2: new VariableType('variableName')
319-
},
320-
id: true,
321-
title: true,
322-
comments: {
323-
__args: {
324-
offensiveOnly: true
325-
},
326-
id: true,
327-
comment: true,
328-
user: true
329-
}
330-
}
331-
}
332-
};
333-
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
334-
`query ($variableName: String!) {
335-
Posts (arg1: 20, arg2: $variableName) {
336-
id
337-
title
338-
comments (offensiveOnly: true) {
339-
id
340-
comment
341-
user
342-
}
343-
}
344-
}`);
345-
});

src/jsonToGraphQLQuery.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {EnumType} from './types/EnumType';
2-
import {VariableType} from './types/VariableType';
1+
import { EnumType } from './types/EnumType';
2+
import { VariableType } from './types/VariableType';
33

44
function stringify(obj_from_json: any): string {
55
if (obj_from_json instanceof EnumType) {
66
return obj_from_json.value;
77
}
8-
// variables should be prefixed with dollar sign and not e quoted
8+
// variables should be prefixed with dollar sign and not quoted
99
else if (obj_from_json instanceof VariableType) {
1010
return `$${obj_from_json.value}`;
1111
}

src/types/__tests__/EnumType.tests.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import { expect } from 'chai';
3+
import { jsonToGraphQLQuery, EnumType } from '../../';
4+
5+
describe('EnumType()', () => {
6+
7+
it('converts a query with enum arguments', () => {
8+
const query = {
9+
query: {
10+
Posts: {
11+
__args: {
12+
status: new EnumType('PUBLISHED')
13+
},
14+
id: true,
15+
title: true,
16+
post_date: true
17+
}
18+
}
19+
};
20+
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
21+
`query {
22+
Posts (status: PUBLISHED) {
23+
id
24+
title
25+
post_date
26+
}
27+
}`);
28+
});
29+
30+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
import { expect } from 'chai';
3+
import { jsonToGraphQLQuery, VariableType } from '../../';
4+
5+
describe('VariableType()', () => {
6+
7+
it('converts query variables', () => {
8+
const query = {
9+
query: {
10+
__variables: {
11+
someString: 'String!',
12+
varWithDefault: 'String = "default_value"'
13+
},
14+
Posts: {
15+
__args: {
16+
arg1: 20,
17+
arg2: new VariableType('someString')
18+
},
19+
id: true,
20+
title: true,
21+
comments: {
22+
__args: {
23+
offensiveOnly: true
24+
},
25+
id: true,
26+
comment: true,
27+
user: true
28+
}
29+
}
30+
}
31+
};
32+
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
33+
`query ($someString: String!, $varWithDefault: String = "default_value") {
34+
Posts (arg1: 20, arg2: $someString) {
35+
id
36+
title
37+
comments (offensiveOnly: true) {
38+
id
39+
comment
40+
user
41+
}
42+
}
43+
}`);
44+
});
45+
46+
});

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"sourceMap": true,
99
"experimentalDecorators": true,
1010
"removeComments": true,
11+
"noUnusedLocals": true,
1112
"lib": [
1213
"es2015"
1314
]

0 commit comments

Comments
 (0)