Skip to content

Commit 9452661

Browse files
committed
Cleanup tests + switch serialization to 'util.inspect'
1 parent 261b99b commit 9452661

File tree

1 file changed

+60
-82
lines changed

1 file changed

+60
-82
lines changed

src/execution/__tests__/variables-test.js

Lines changed: 60 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import { inspect } from 'util';
89
import { expect } from 'chai';
910
import { describe, it } from 'mocha';
1011
import { execute } from '../execute';
@@ -59,67 +60,44 @@ const TestNestedInputObject = new GraphQLInputObjectType({
5960
},
6061
});
6162

63+
function fieldWithInputArg(inputArg) {
64+
return {
65+
type: GraphQLString,
66+
args: { input: inputArg },
67+
resolve(_, args) {
68+
if (args.hasOwnProperty('input')) {
69+
return inspect(args.input, { depth: null });
70+
}
71+
},
72+
};
73+
}
74+
6275
const TestType = new GraphQLObjectType({
6376
name: 'TestType',
6477
fields: {
65-
fieldWithObjectInput: {
66-
type: GraphQLString,
67-
args: { input: { type: TestInputObject } },
68-
resolve: (_, { input }) => input && JSON.stringify(input),
69-
},
70-
fieldWithNullableStringInput: {
71-
type: GraphQLString,
72-
args: { input: { type: GraphQLString } },
73-
resolve: (_, { input }) => input && JSON.stringify(input),
74-
},
75-
fieldWithNonNullableStringInput: {
76-
type: GraphQLString,
77-
args: { input: { type: GraphQLNonNull(GraphQLString) } },
78-
resolve: (_, { input }) => input && JSON.stringify(input),
79-
},
80-
fieldWithDefaultArgumentValue: {
78+
fieldWithObjectInput: fieldWithInputArg({ type: TestInputObject }),
79+
fieldWithNullableStringInput: fieldWithInputArg({ type: GraphQLString }),
80+
fieldWithNonNullableStringInput: fieldWithInputArg({
81+
type: GraphQLNonNull(GraphQLString),
82+
}),
83+
fieldWithDefaultArgumentValue: fieldWithInputArg({
8184
type: GraphQLString,
82-
args: { input: { type: GraphQLString, defaultValue: 'Hello World' } },
83-
resolve: (_, { input }) => input && JSON.stringify(input),
84-
},
85-
fieldWithNestedInputObject: {
86-
type: GraphQLString,
87-
args: {
88-
input: {
89-
type: TestNestedInputObject,
90-
defaultValue: 'Hello World',
91-
},
92-
},
93-
resolve: (_, { input }) => input && JSON.stringify(input),
94-
},
95-
list: {
96-
type: GraphQLString,
97-
args: { input: { type: GraphQLList(GraphQLString) } },
98-
resolve: (_, { input }) => input && JSON.stringify(input),
99-
},
100-
nnList: {
101-
type: GraphQLString,
102-
args: {
103-
input: { type: GraphQLNonNull(GraphQLList(GraphQLString)) },
104-
},
105-
resolve: (_, { input }) => input && JSON.stringify(input),
106-
},
107-
listNN: {
108-
type: GraphQLString,
109-
args: {
110-
input: { type: GraphQLList(GraphQLNonNull(GraphQLString)) },
111-
},
112-
resolve: (_, { input }) => input && JSON.stringify(input),
113-
},
114-
nnListNN: {
115-
type: GraphQLString,
116-
args: {
117-
input: {
118-
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLString))),
119-
},
120-
},
121-
resolve: (_, { input }) => input && JSON.stringify(input),
122-
},
85+
defaultValue: 'Hello World',
86+
}),
87+
fieldWithNestedInputObject: fieldWithInputArg({
88+
type: TestNestedInputObject,
89+
defaultValue: 'Hello World',
90+
}),
91+
list: fieldWithInputArg({ type: GraphQLList(GraphQLString) }),
92+
nnList: fieldWithInputArg({
93+
type: GraphQLNonNull(GraphQLList(GraphQLString)),
94+
}),
95+
listNN: fieldWithInputArg({
96+
type: GraphQLList(GraphQLNonNull(GraphQLString)),
97+
}),
98+
nnListNN: fieldWithInputArg({
99+
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLString))),
100+
}),
123101
},
124102
});
125103

@@ -138,7 +116,7 @@ describe('Execute: Handles inputs', () => {
138116

139117
expect(await execute(schema, ast)).to.deep.equal({
140118
data: {
141-
fieldWithObjectInput: '{"a":"foo","b":["bar"],"c":"baz"}',
119+
fieldWithObjectInput: "{ a: 'foo', b: [ 'bar' ], c: 'baz' }",
142120
},
143121
});
144122
});
@@ -153,7 +131,7 @@ describe('Execute: Handles inputs', () => {
153131

154132
expect(await execute(schema, ast)).to.deep.equal({
155133
data: {
156-
fieldWithObjectInput: '{"a":"foo","b":["bar"],"c":"baz"}',
134+
fieldWithObjectInput: "{ a: 'foo', b: [ 'bar' ], c: 'baz' }",
157135
},
158136
});
159137
});
@@ -168,7 +146,7 @@ describe('Execute: Handles inputs', () => {
168146

169147
expect(await execute(schema, ast)).to.deep.equal({
170148
data: {
171-
fieldWithObjectInput: '{"a":null,"b":null,"c":"C","d":null}',
149+
fieldWithObjectInput: "{ a: null, b: null, c: 'C', d: null }",
172150
},
173151
});
174152
});
@@ -183,7 +161,7 @@ describe('Execute: Handles inputs', () => {
183161

184162
expect(await execute(schema, ast)).to.deep.equal({
185163
data: {
186-
fieldWithObjectInput: '{"b":["A",null,"C"],"c":"C"}',
164+
fieldWithObjectInput: "{ b: [ 'A', null, 'C' ], c: 'C' }",
187165
},
188166
});
189167
});
@@ -223,7 +201,7 @@ describe('Execute: Handles inputs', () => {
223201

224202
expect(await execute(schema, ast)).to.deep.equal({
225203
data: {
226-
fieldWithObjectInput: '{"c":"foo","d":"DeserializedValue"}',
204+
fieldWithObjectInput: "{ c: 'foo', d: 'DeserializedValue' }",
227205
},
228206
});
229207
});
@@ -243,7 +221,7 @@ describe('Execute: Handles inputs', () => {
243221

244222
expect(result).to.deep.equal({
245223
data: {
246-
fieldWithObjectInput: '{"a":"foo","b":["bar"],"c":"baz"}',
224+
fieldWithObjectInput: "{ a: 'foo', b: [ 'bar' ], c: 'baz' }",
247225
},
248226
});
249227
});
@@ -259,7 +237,7 @@ describe('Execute: Handles inputs', () => {
259237

260238
expect(result).to.deep.equal({
261239
data: {
262-
fieldWithObjectInput: '{"a":"foo","b":["bar"],"c":"baz"}',
240+
fieldWithObjectInput: "{ a: 'foo', b: [ 'bar' ], c: 'baz' }",
263241
},
264242
});
265243
});
@@ -270,7 +248,7 @@ describe('Execute: Handles inputs', () => {
270248

271249
expect(result).to.deep.equal({
272250
data: {
273-
fieldWithObjectInput: '{"a":"foo","b":["bar"],"c":"baz"}',
251+
fieldWithObjectInput: "{ a: 'foo', b: [ 'bar' ], c: 'baz' }",
274252
},
275253
});
276254
});
@@ -281,7 +259,7 @@ describe('Execute: Handles inputs', () => {
281259

282260
expect(result).to.deep.equal({
283261
data: {
284-
fieldWithObjectInput: '{"c":"foo","d":"DeserializedValue"}',
262+
fieldWithObjectInput: "{ c: 'foo', d: 'DeserializedValue' }",
285263
},
286264
});
287265
});
@@ -448,7 +426,7 @@ describe('Execute: Handles inputs', () => {
448426
await execute(schema, ast, null, null, { value: null }),
449427
).to.deep.equal({
450428
data: {
451-
fieldWithNullableStringInput: null,
429+
fieldWithNullableStringInput: 'null',
452430
},
453431
});
454432
});
@@ -465,7 +443,7 @@ describe('Execute: Handles inputs', () => {
465443
await execute(schema, ast, null, null, { value: 'a' }),
466444
).to.deep.equal({
467445
data: {
468-
fieldWithNullableStringInput: '"a"',
446+
fieldWithNullableStringInput: "'a'",
469447
},
470448
});
471449
});
@@ -480,7 +458,7 @@ describe('Execute: Handles inputs', () => {
480458

481459
expect(await execute(schema, ast)).to.deep.equal({
482460
data: {
483-
fieldWithNullableStringInput: '"a"',
461+
fieldWithNullableStringInput: "'a'",
484462
},
485463
});
486464
});
@@ -496,7 +474,7 @@ describe('Execute: Handles inputs', () => {
496474

497475
expect(await execute(schema, parse(doc))).to.deep.equal({
498476
data: {
499-
fieldWithNonNullableStringInput: '"default"',
477+
fieldWithNonNullableStringInput: "'default'",
500478
},
501479
});
502480
});
@@ -555,7 +533,7 @@ describe('Execute: Handles inputs', () => {
555533
await execute(schema, ast, null, null, { value: 'a' }),
556534
).to.deep.equal({
557535
data: {
558-
fieldWithNonNullableStringInput: '"a"',
536+
fieldWithNonNullableStringInput: "'a'",
559537
},
560538
});
561539
});
@@ -570,7 +548,7 @@ describe('Execute: Handles inputs', () => {
570548

571549
expect(await execute(schema, ast)).to.deep.equal({
572550
data: {
573-
fieldWithNonNullableStringInput: '"a"',
551+
fieldWithNonNullableStringInput: "'a'",
574552
},
575553
});
576554
});
@@ -681,7 +659,7 @@ describe('Execute: Handles inputs', () => {
681659
await execute(schema, ast, null, null, { input: null }),
682660
).to.deep.equal({
683661
data: {
684-
list: null,
662+
list: 'null',
685663
},
686664
});
687665
});
@@ -698,7 +676,7 @@ describe('Execute: Handles inputs', () => {
698676
await execute(schema, ast, null, null, { input: ['A'] }),
699677
).to.deep.equal({
700678
data: {
701-
list: '["A"]',
679+
list: "[ 'A' ]",
702680
},
703681
});
704682
});
@@ -715,7 +693,7 @@ describe('Execute: Handles inputs', () => {
715693
await execute(schema, ast, null, null, { input: ['A', null, 'B'] }),
716694
).to.deep.equal({
717695
data: {
718-
list: '["A",null,"B"]',
696+
list: "[ 'A', null, 'B' ]",
719697
},
720698
});
721699
});
@@ -754,7 +732,7 @@ describe('Execute: Handles inputs', () => {
754732
await execute(schema, ast, null, null, { input: ['A'] }),
755733
).to.deep.equal({
756734
data: {
757-
nnList: '["A"]',
735+
nnList: "[ 'A' ]",
758736
},
759737
});
760738
});
@@ -771,7 +749,7 @@ describe('Execute: Handles inputs', () => {
771749
await execute(schema, ast, null, null, { input: ['A', null, 'B'] }),
772750
).to.deep.equal({
773751
data: {
774-
nnList: '["A",null,"B"]',
752+
nnList: "[ 'A', null, 'B' ]",
775753
},
776754
});
777755
});
@@ -788,7 +766,7 @@ describe('Execute: Handles inputs', () => {
788766
await execute(schema, ast, null, null, { input: null }),
789767
).to.deep.equal({
790768
data: {
791-
listNN: null,
769+
listNN: 'null',
792770
},
793771
});
794772
});
@@ -805,7 +783,7 @@ describe('Execute: Handles inputs', () => {
805783
await execute(schema, ast, null, null, { input: ['A'] }),
806784
).to.deep.equal({
807785
data: {
808-
listNN: '["A"]',
786+
listNN: "[ 'A' ]",
809787
},
810788
});
811789
});
@@ -867,7 +845,7 @@ describe('Execute: Handles inputs', () => {
867845
await execute(schema, ast, null, null, { input: ['A'] }),
868846
).to.deep.equal({
869847
data: {
870-
nnListNN: '["A"]',
848+
nnListNN: "[ 'A' ]",
871849
},
872850
});
873851
});
@@ -950,7 +928,7 @@ describe('Execute: Handles inputs', () => {
950928

951929
expect(await execute(schema, ast)).to.deep.equal({
952930
data: {
953-
fieldWithDefaultArgumentValue: '"Hello World"',
931+
fieldWithDefaultArgumentValue: "'Hello World'",
954932
},
955933
});
956934
});
@@ -962,7 +940,7 @@ describe('Execute: Handles inputs', () => {
962940

963941
expect(await execute(schema, ast)).to.deep.equal({
964942
data: {
965-
fieldWithDefaultArgumentValue: '"Hello World"',
943+
fieldWithDefaultArgumentValue: "'Hello World'",
966944
},
967945
});
968946
});

0 commit comments

Comments
 (0)