@@ -6,7 +6,7 @@ import NIO
6
6
class InputTests : XCTestCase {
7
7
8
8
// Test that input objects parse as expected from non-null literals
9
- func testInputParsing ( ) throws {
9
+ func testInputNoNull ( ) throws {
10
10
struct Echo : Codable {
11
11
let field1 : String ?
12
12
let field2 : String ?
@@ -86,6 +86,7 @@ class InputTests : XCTestCase {
86
86
XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
87
87
}
88
88
89
+ // Test in arguments
89
90
XCTAssertEqual (
90
91
try graphql (
91
92
schema: schema,
@@ -109,6 +110,34 @@ class InputTests : XCTestCase {
109
110
]
110
111
] )
111
112
)
113
+
114
+ // Test in variables
115
+ XCTAssertEqual (
116
+ try graphql (
117
+ schema: schema,
118
+ request: """
119
+ query echo($input: EchoInput) {
120
+ echo(input: $input) {
121
+ field1
122
+ field2
123
+ }
124
+ }
125
+ """ ,
126
+ eventLoopGroup: group,
127
+ variableValues: [
128
+ " input " : [
129
+ " field1 " : " value1 " ,
130
+ " field2 " : " value2 "
131
+ ]
132
+ ]
133
+ ) . wait ( ) ,
134
+ GraphQLResult ( data: [
135
+ " echo " : [
136
+ " field1 " : " value1 " ,
137
+ " field2 " : " value2 " ,
138
+ ]
139
+ ] )
140
+ )
112
141
}
113
142
114
143
// Test that inputs parse as expected when null literals are present
@@ -192,6 +221,7 @@ class InputTests : XCTestCase {
192
221
XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
193
222
}
194
223
224
+ // Test in arguments
195
225
XCTAssertEqual (
196
226
try graphql (
197
227
schema: schema,
@@ -215,6 +245,34 @@ class InputTests : XCTestCase {
215
245
]
216
246
] )
217
247
)
248
+
249
+ // Test in variables
250
+ XCTAssertEqual (
251
+ try graphql (
252
+ schema: schema,
253
+ request: """
254
+ query echo($input: EchoInput) {
255
+ echo(input: $input) {
256
+ field1
257
+ field2
258
+ }
259
+ }
260
+ """ ,
261
+ eventLoopGroup: group,
262
+ variableValues: [
263
+ " input " : [
264
+ " field1 " : " value1 " ,
265
+ " field2 " : . null
266
+ ]
267
+ ]
268
+ ) . wait ( ) ,
269
+ GraphQLResult ( data: [
270
+ " echo " : [
271
+ " field1 " : " value1 " ,
272
+ " field2 " : nil ,
273
+ ]
274
+ ] )
275
+ )
218
276
}
219
277
220
278
// Test that input objects parse as expected when there are missing fields with no default
@@ -298,6 +356,7 @@ class InputTests : XCTestCase {
298
356
XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
299
357
}
300
358
359
+ // Test in arguments
301
360
XCTAssertEqual (
302
361
try graphql (
303
362
schema: schema,
@@ -320,6 +379,33 @@ class InputTests : XCTestCase {
320
379
]
321
380
] )
322
381
)
382
+
383
+ // Test in variables
384
+ XCTAssertEqual (
385
+ try graphql (
386
+ schema: schema,
387
+ request: """
388
+ query echo($input: EchoInput) {
389
+ echo(input: $input) {
390
+ field1
391
+ field2
392
+ }
393
+ }
394
+ """ ,
395
+ eventLoopGroup: group,
396
+ variableValues: [
397
+ " input " : [
398
+ " field1 " : " value1 "
399
+ ]
400
+ ]
401
+ ) . wait ( ) ,
402
+ GraphQLResult ( data: [
403
+ " echo " : [
404
+ " field1 " : " value1 " ,
405
+ " field2 " : nil ,
406
+ ]
407
+ ] )
408
+ )
323
409
}
324
410
325
411
// Test that input objects parse as expected when there are missing fields with defaults
@@ -404,13 +490,38 @@ class InputTests : XCTestCase {
404
490
XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
405
491
}
406
492
493
+ // Undefined with default gets default
494
+ XCTAssertEqual (
495
+ try graphql (
496
+ schema: schema,
497
+ request: """
498
+ {
499
+ echo(input:{
500
+ field1: " value1 "
501
+ }) {
502
+ field1
503
+ field2
504
+ }
505
+ }
506
+ """ ,
507
+ eventLoopGroup: group
508
+ ) . wait ( ) ,
509
+ GraphQLResult ( data: [
510
+ " echo " : [
511
+ " field1 " : " value1 " ,
512
+ " field2 " : " value2 " ,
513
+ ]
514
+ ] )
515
+ )
516
+ // Null literal with default gets null
407
517
XCTAssertEqual (
408
518
try graphql (
409
519
schema: schema,
410
520
request: """
411
521
{
412
522
echo(input:{
413
523
field1: " value1 "
524
+ field2: null
414
525
}) {
415
526
field1
416
527
field2
@@ -419,12 +530,67 @@ class InputTests : XCTestCase {
419
530
""" ,
420
531
eventLoopGroup: group
421
532
) . wait ( ) ,
533
+ GraphQLResult ( data: [
534
+ " echo " : [
535
+ " field1 " : " value1 " ,
536
+ " field2 " : nil ,
537
+ ]
538
+ ] )
539
+ )
540
+
541
+ // Test in variable
542
+ // Undefined with default gets default
543
+ XCTAssertEqual (
544
+ try graphql (
545
+ schema: schema,
546
+ request: """
547
+ query echo($input: EchoInput) {
548
+ echo(input: $input) {
549
+ field1
550
+ field2
551
+ }
552
+ }
553
+ """ ,
554
+ eventLoopGroup: group,
555
+ variableValues: [
556
+ " input " : [
557
+ " field1 " : " value1 "
558
+ ]
559
+ ]
560
+ ) . wait ( ) ,
422
561
GraphQLResult ( data: [
423
562
" echo " : [
424
563
" field1 " : " value1 " ,
425
564
" field2 " : " value2 " ,
426
565
]
427
566
] )
428
567
)
568
+ // Null literal with default gets null
569
+ XCTAssertEqual (
570
+ try graphql (
571
+ schema: schema,
572
+ request: """
573
+ query echo($input: EchoInput) {
574
+ echo(input: $input) {
575
+ field1
576
+ field2
577
+ }
578
+ }
579
+ """ ,
580
+ eventLoopGroup: group,
581
+ variableValues: [
582
+ " input " : [
583
+ " field1 " : " value1 " ,
584
+ " field2 " : . null
585
+ ]
586
+ ]
587
+ ) . wait ( ) ,
588
+ GraphQLResult ( data: [
589
+ " echo " : [
590
+ " field1 " : " value1 " ,
591
+ " field2 " : nil ,
592
+ ]
593
+ ] )
594
+ )
429
595
}
430
596
}
0 commit comments