5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
+ import { inspect } from 'util' ;
8
9
import { expect } from 'chai' ;
9
10
import { describe , it } from 'mocha' ;
10
11
import { execute } from '../execute' ;
@@ -59,67 +60,44 @@ const TestNestedInputObject = new GraphQLInputObjectType({
59
60
} ,
60
61
} ) ;
61
62
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
+
62
75
const TestType = new GraphQLObjectType ( {
63
76
name : 'TestType' ,
64
77
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 ( {
81
84
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
+ } ) ,
123
101
} ,
124
102
} ) ;
125
103
@@ -138,7 +116,7 @@ describe('Execute: Handles inputs', () => {
138
116
139
117
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
140
118
data : {
141
- fieldWithObjectInput : '{"a":" foo","b":[" bar"],"c":" baz"}' ,
119
+ fieldWithObjectInput : "{ a: ' foo', b: [ ' bar' ], c: ' baz' }" ,
142
120
} ,
143
121
} ) ;
144
122
} ) ;
@@ -153,7 +131,7 @@ describe('Execute: Handles inputs', () => {
153
131
154
132
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
155
133
data : {
156
- fieldWithObjectInput : '{"a":" foo","b":[" bar"],"c":" baz"}' ,
134
+ fieldWithObjectInput : "{ a: ' foo', b: [ ' bar' ], c: ' baz' }" ,
157
135
} ,
158
136
} ) ;
159
137
} ) ;
@@ -168,7 +146,7 @@ describe('Execute: Handles inputs', () => {
168
146
169
147
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
170
148
data : {
171
- fieldWithObjectInput : '{"a": null,"b": null,"c":"C","d": null}' ,
149
+ fieldWithObjectInput : "{ a: null, b: null, c: 'C', d: null }" ,
172
150
} ,
173
151
} ) ;
174
152
} ) ;
@@ -183,7 +161,7 @@ describe('Execute: Handles inputs', () => {
183
161
184
162
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
185
163
data : {
186
- fieldWithObjectInput : '{"b":["A", null,"C"],"c":"C"}' ,
164
+ fieldWithObjectInput : "{ b: [ 'A', null, 'C' ], c: 'C' }" ,
187
165
} ,
188
166
} ) ;
189
167
} ) ;
@@ -223,7 +201,7 @@ describe('Execute: Handles inputs', () => {
223
201
224
202
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
225
203
data : {
226
- fieldWithObjectInput : '{"c":" foo","d":" DeserializedValue"}' ,
204
+ fieldWithObjectInput : "{ c: ' foo', d: ' DeserializedValue' }" ,
227
205
} ,
228
206
} ) ;
229
207
} ) ;
@@ -243,7 +221,7 @@ describe('Execute: Handles inputs', () => {
243
221
244
222
expect ( result ) . to . deep . equal ( {
245
223
data : {
246
- fieldWithObjectInput : '{"a":" foo","b":[" bar"],"c":" baz"}' ,
224
+ fieldWithObjectInput : "{ a: ' foo', b: [ ' bar' ], c: ' baz' }" ,
247
225
} ,
248
226
} ) ;
249
227
} ) ;
@@ -259,7 +237,7 @@ describe('Execute: Handles inputs', () => {
259
237
260
238
expect ( result ) . to . deep . equal ( {
261
239
data : {
262
- fieldWithObjectInput : '{"a":" foo","b":[" bar"],"c":" baz"}' ,
240
+ fieldWithObjectInput : "{ a: ' foo', b: [ ' bar' ], c: ' baz' }" ,
263
241
} ,
264
242
} ) ;
265
243
} ) ;
@@ -270,7 +248,7 @@ describe('Execute: Handles inputs', () => {
270
248
271
249
expect ( result ) . to . deep . equal ( {
272
250
data : {
273
- fieldWithObjectInput : '{"a":" foo","b":[" bar"],"c":" baz"}' ,
251
+ fieldWithObjectInput : "{ a: ' foo', b: [ ' bar' ], c: ' baz' }" ,
274
252
} ,
275
253
} ) ;
276
254
} ) ;
@@ -281,7 +259,7 @@ describe('Execute: Handles inputs', () => {
281
259
282
260
expect ( result ) . to . deep . equal ( {
283
261
data : {
284
- fieldWithObjectInput : '{"c":" foo","d":" DeserializedValue"}' ,
262
+ fieldWithObjectInput : "{ c: ' foo', d: ' DeserializedValue' }" ,
285
263
} ,
286
264
} ) ;
287
265
} ) ;
@@ -448,7 +426,7 @@ describe('Execute: Handles inputs', () => {
448
426
await execute ( schema , ast , null , null , { value : null } ) ,
449
427
) . to . deep . equal ( {
450
428
data : {
451
- fieldWithNullableStringInput : null ,
429
+ fieldWithNullableStringInput : ' null' ,
452
430
} ,
453
431
} ) ;
454
432
} ) ;
@@ -465,7 +443,7 @@ describe('Execute: Handles inputs', () => {
465
443
await execute ( schema , ast , null , null , { value : 'a' } ) ,
466
444
) . to . deep . equal ( {
467
445
data : {
468
- fieldWithNullableStringInput : '"a"' ,
446
+ fieldWithNullableStringInput : "'a'" ,
469
447
} ,
470
448
} ) ;
471
449
} ) ;
@@ -480,7 +458,7 @@ describe('Execute: Handles inputs', () => {
480
458
481
459
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
482
460
data : {
483
- fieldWithNullableStringInput : '"a"' ,
461
+ fieldWithNullableStringInput : "'a'" ,
484
462
} ,
485
463
} ) ;
486
464
} ) ;
@@ -496,7 +474,7 @@ describe('Execute: Handles inputs', () => {
496
474
497
475
expect ( await execute ( schema , parse ( doc ) ) ) . to . deep . equal ( {
498
476
data : {
499
- fieldWithNonNullableStringInput : '" default"' ,
477
+ fieldWithNonNullableStringInput : "' default'" ,
500
478
} ,
501
479
} ) ;
502
480
} ) ;
@@ -555,7 +533,7 @@ describe('Execute: Handles inputs', () => {
555
533
await execute ( schema , ast , null , null , { value : 'a' } ) ,
556
534
) . to . deep . equal ( {
557
535
data : {
558
- fieldWithNonNullableStringInput : '"a"' ,
536
+ fieldWithNonNullableStringInput : "'a'" ,
559
537
} ,
560
538
} ) ;
561
539
} ) ;
@@ -570,7 +548,7 @@ describe('Execute: Handles inputs', () => {
570
548
571
549
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
572
550
data : {
573
- fieldWithNonNullableStringInput : '"a"' ,
551
+ fieldWithNonNullableStringInput : "'a'" ,
574
552
} ,
575
553
} ) ;
576
554
} ) ;
@@ -681,7 +659,7 @@ describe('Execute: Handles inputs', () => {
681
659
await execute ( schema , ast , null , null , { input : null } ) ,
682
660
) . to . deep . equal ( {
683
661
data : {
684
- list : null ,
662
+ list : ' null' ,
685
663
} ,
686
664
} ) ;
687
665
} ) ;
@@ -698,7 +676,7 @@ describe('Execute: Handles inputs', () => {
698
676
await execute ( schema , ast , null , null , { input : [ 'A' ] } ) ,
699
677
) . to . deep . equal ( {
700
678
data : {
701
- list : '["A"]' ,
679
+ list : "[ 'A' ]" ,
702
680
} ,
703
681
} ) ;
704
682
} ) ;
@@ -715,7 +693,7 @@ describe('Execute: Handles inputs', () => {
715
693
await execute ( schema , ast , null , null , { input : [ 'A' , null , 'B' ] } ) ,
716
694
) . to . deep . equal ( {
717
695
data : {
718
- list : '["A", null,"B"]' ,
696
+ list : "[ 'A', null, 'B' ]" ,
719
697
} ,
720
698
} ) ;
721
699
} ) ;
@@ -754,7 +732,7 @@ describe('Execute: Handles inputs', () => {
754
732
await execute ( schema , ast , null , null , { input : [ 'A' ] } ) ,
755
733
) . to . deep . equal ( {
756
734
data : {
757
- nnList : '["A"]' ,
735
+ nnList : "[ 'A' ]" ,
758
736
} ,
759
737
} ) ;
760
738
} ) ;
@@ -771,7 +749,7 @@ describe('Execute: Handles inputs', () => {
771
749
await execute ( schema , ast , null , null , { input : [ 'A' , null , 'B' ] } ) ,
772
750
) . to . deep . equal ( {
773
751
data : {
774
- nnList : '["A", null,"B"]' ,
752
+ nnList : "[ 'A', null, 'B' ]" ,
775
753
} ,
776
754
} ) ;
777
755
} ) ;
@@ -788,7 +766,7 @@ describe('Execute: Handles inputs', () => {
788
766
await execute ( schema , ast , null , null , { input : null } ) ,
789
767
) . to . deep . equal ( {
790
768
data : {
791
- listNN : null ,
769
+ listNN : ' null' ,
792
770
} ,
793
771
} ) ;
794
772
} ) ;
@@ -805,7 +783,7 @@ describe('Execute: Handles inputs', () => {
805
783
await execute ( schema , ast , null , null , { input : [ 'A' ] } ) ,
806
784
) . to . deep . equal ( {
807
785
data : {
808
- listNN : '["A"]' ,
786
+ listNN : "[ 'A' ]" ,
809
787
} ,
810
788
} ) ;
811
789
} ) ;
@@ -867,7 +845,7 @@ describe('Execute: Handles inputs', () => {
867
845
await execute ( schema , ast , null , null , { input : [ 'A' ] } ) ,
868
846
) . to . deep . equal ( {
869
847
data : {
870
- nnListNN : '["A"]' ,
848
+ nnListNN : "[ 'A' ]" ,
871
849
} ,
872
850
} ) ;
873
851
} ) ;
@@ -950,7 +928,7 @@ describe('Execute: Handles inputs', () => {
950
928
951
929
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
952
930
data : {
953
- fieldWithDefaultArgumentValue : '" Hello World"' ,
931
+ fieldWithDefaultArgumentValue : "' Hello World'" ,
954
932
} ,
955
933
} ) ;
956
934
} ) ;
@@ -962,7 +940,7 @@ describe('Execute: Handles inputs', () => {
962
940
963
941
expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
964
942
data : {
965
- fieldWithDefaultArgumentValue : '" Hello World"' ,
943
+ fieldWithDefaultArgumentValue : "' Hello World'" ,
966
944
} ,
967
945
} ) ;
968
946
} ) ;
0 commit comments