@@ -6,7 +6,7 @@ import NIO
66class InputTests : XCTestCase {
77
88 // Test that input objects parse as expected from non-null literals
9- func testInputParsing ( ) throws {
9+ func testInputNoNull ( ) throws {
1010 struct Echo : Codable {
1111 let field1 : String ?
1212 let field2 : String ?
@@ -86,6 +86,7 @@ class InputTests : XCTestCase {
8686 XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
8787 }
8888
89+ // Test in arguments
8990 XCTAssertEqual (
9091 try graphql (
9192 schema: schema,
@@ -109,6 +110,34 @@ class InputTests : XCTestCase {
109110 ]
110111 ] )
111112 )
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+ )
112141 }
113142
114143 // Test that inputs parse as expected when null literals are present
@@ -192,6 +221,7 @@ class InputTests : XCTestCase {
192221 XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
193222 }
194223
224+ // Test in arguments
195225 XCTAssertEqual (
196226 try graphql (
197227 schema: schema,
@@ -215,6 +245,34 @@ class InputTests : XCTestCase {
215245 ]
216246 ] )
217247 )
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+ )
218276 }
219277
220278 // Test that input objects parse as expected when there are missing fields with no default
@@ -298,6 +356,7 @@ class InputTests : XCTestCase {
298356 XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
299357 }
300358
359+ // Test in arguments
301360 XCTAssertEqual (
302361 try graphql (
303362 schema: schema,
@@ -320,6 +379,33 @@ class InputTests : XCTestCase {
320379 ]
321380 ] )
322381 )
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+ )
323409 }
324410
325411 // Test that input objects parse as expected when there are missing fields with defaults
@@ -404,13 +490,38 @@ class InputTests : XCTestCase {
404490 XCTAssertNoThrow ( try group. syncShutdownGracefully ( ) )
405491 }
406492
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
407517 XCTAssertEqual (
408518 try graphql (
409519 schema: schema,
410520 request: """
411521 {
412522 echo(input:{
413523 field1: " value1 "
524+ field2: null
414525 }) {
415526 field1
416527 field2
@@ -419,12 +530,67 @@ class InputTests : XCTestCase {
419530 """ ,
420531 eventLoopGroup: group
421532 ) . 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 ( ) ,
422561 GraphQLResult ( data: [
423562 " echo " : [
424563 " field1 " : " value1 " ,
425564 " field2 " : " value2 " ,
426565 ]
427566 ] )
428567 )
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+ )
429595 }
430596}
0 commit comments