@@ -199,24 +199,30 @@ describe('Execute: Handles inputs', () => {
199
199
200
200
const result = await execute ( schema , ast ) ;
201
201
202
- expect ( result ) . to . deep . equal ( {
202
+ expect ( result ) . to . containSubset ( {
203
203
data : {
204
204
fieldWithObjectInput : null
205
- }
205
+ } ,
206
+ errors : [ {
207
+ message :
208
+ 'Argument "input" got invalid value ["foo", "bar", "baz"].\n' +
209
+ 'Expected "TestInputObject", found not an object.' ,
210
+ path : [ 'fieldWithObjectInput' ]
211
+ } ]
206
212
} ) ;
207
213
} ) ;
208
214
209
215
it ( 'properly runs parseLiteral on complex scalar types' , async ( ) => {
210
216
const doc = `
211
217
{
212
- fieldWithObjectInput(input: {a : "foo", d: "SerializedValue"})
218
+ fieldWithObjectInput(input: {c : "foo", d: "SerializedValue"})
213
219
}
214
220
` ;
215
221
const ast = parse ( doc ) ;
216
222
217
223
return expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
218
224
data : {
219
- fieldWithObjectInput : '{"a ":"foo","d":"DeserializedValue"}' ,
225
+ fieldWithObjectInput : '{"c ":"foo","d":"DeserializedValue"}' ,
220
226
}
221
227
} ) ;
222
228
} ) ;
@@ -482,7 +488,21 @@ describe('Execute: Handles inputs', () => {
482
488
} ) ;
483
489
} ) ;
484
490
485
- describe ( 'Handles non-nullable scalars' , ( ) => {
491
+ describe ( 'Handles non-nullable scalars' , async ( ) => {
492
+ it ( 'allows non-nullable inputs to be omitted given a default' , async ( ) => {
493
+ const doc = `
494
+ query SetsNonNullable($value: String = "default") {
495
+ fieldWithNonNullableStringInput(input: $value)
496
+ }
497
+ ` ;
498
+
499
+ expect ( await execute ( schema , parse ( doc ) ) ) . to . deep . equal ( {
500
+ data : {
501
+ fieldWithNonNullableStringInput : '"default"'
502
+ }
503
+ } ) ;
504
+ } ) ;
505
+
486
506
it ( 'does not allow non-nullable inputs to be omitted in a variable' , async ( ) => {
487
507
const doc = `
488
508
query SetsNonNullable($value: String!) {
@@ -522,7 +542,8 @@ describe('Execute: Handles inputs', () => {
522
542
expect ( caughtError ) . to . containSubset ( {
523
543
locations : [ { line : 2 , column : 31 } ] ,
524
544
message :
525
- 'Variable "$value" of required type "String!" was not provided.'
545
+ 'Variable "$value" got invalid value null.\n' +
546
+ 'Expected "String!", found null.'
526
547
} ) ;
527
548
} ) ;
528
549
@@ -558,7 +579,7 @@ describe('Execute: Handles inputs', () => {
558
579
} ) ;
559
580
} ) ;
560
581
561
- it ( 'passes along null for non-nullable inputs if explcitly set in the query ' , async ( ) => {
582
+ it ( 'reports error for missing non-nullable inputs' , async ( ) => {
562
583
const doc = `
563
584
{
564
585
fieldWithNonNullableStringInput
@@ -569,7 +590,39 @@ describe('Execute: Handles inputs', () => {
569
590
return expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
570
591
data : {
571
592
fieldWithNonNullableStringInput : null
572
- }
593
+ } ,
594
+ errors : [ {
595
+ message : 'Argument "input" of required type "String!" was not provided.' ,
596
+ locations : [ { line : 3 , column : 9 } ] ,
597
+ path : [ 'fieldWithNonNullableStringInput' ]
598
+ } ]
599
+ } ) ;
600
+ } ) ;
601
+
602
+ it ( 'reports error for non-provided variables for non-nullable inputs' , async ( ) => {
603
+ // Note: this test would typically fail validation before encountering
604
+ // this execution error, however for queries which previously validated
605
+ // and are being run against a new schema which have introduced a breaking
606
+ // change to make a formerly non-required argument required, this asserts
607
+ // failure before allowing the underlying code to receive a non-null value.
608
+ const doc = `
609
+ {
610
+ fieldWithNonNullableStringInput(input: $foo)
611
+ }
612
+ ` ;
613
+ const ast = parse ( doc ) ;
614
+
615
+ return expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
616
+ data : {
617
+ fieldWithNonNullableStringInput : null
618
+ } ,
619
+ errors : [ {
620
+ message :
621
+ 'Argument "input" of required type "String!" was provided the ' +
622
+ 'variable "$foo" which was not provided a runtime value.' ,
623
+ locations : [ { line : 3 , column : 48 } ] ,
624
+ path : [ 'fieldWithNonNullableStringInput' ]
625
+ } ]
573
626
} ) ;
574
627
} ) ;
575
628
} ) ;
@@ -644,7 +697,8 @@ describe('Execute: Handles inputs', () => {
644
697
expect ( caughtError ) . to . containSubset ( {
645
698
locations : [ { line : 2 , column : 17 } ] ,
646
699
message :
647
- 'Variable "$input" of required type "[String]!" was not provided.'
700
+ 'Variable "$input" got invalid value null.\n' +
701
+ 'Expected "[String]!", found null.'
648
702
} ) ;
649
703
} ) ;
650
704
@@ -758,7 +812,8 @@ describe('Execute: Handles inputs', () => {
758
812
expect ( caughtError ) . to . containSubset ( {
759
813
locations : [ { line : 2 , column : 17 } ] ,
760
814
message :
761
- 'Variable "$input" of required type "[String!]!" was not provided.'
815
+ 'Variable "$input" got invalid value null.\n' +
816
+ 'Expected "[String!]!", found null.'
762
817
} ) ;
763
818
} ) ;
764
819
@@ -820,7 +875,7 @@ describe('Execute: Handles inputs', () => {
820
875
}
821
876
822
877
expect ( caughtError ) . to . containSubset ( {
823
- locations : [ { line : 2 , column : 17 } ] ,
878
+ locations : [ { line : 2 , column : 25 } ] ,
824
879
message :
825
880
'Variable "$input" expected value of type "TestType!" which cannot ' +
826
881
'be used as an input type.'
@@ -844,7 +899,7 @@ describe('Execute: Handles inputs', () => {
844
899
}
845
900
846
901
expect ( caughtError ) . to . containSubset ( {
847
- locations : [ { line : 2 , column : 17 } ] ,
902
+ locations : [ { line : 2 , column : 25 } ] ,
848
903
message :
849
904
'Variable "$input" expected value of type "UnknownType!" which ' +
850
905
'cannot be used as an input type.'
@@ -867,7 +922,7 @@ describe('Execute: Handles inputs', () => {
867
922
} ) ;
868
923
} ) ;
869
924
870
- it ( 'when nullable variable provided' , async ( ) => {
925
+ it ( 'when omitted variable provided' , async ( ) => {
871
926
const ast = parse ( `query optionalVariable($optional: String) {
872
927
fieldWithDefaultArgumentValue(input: $optional)
873
928
}` ) ;
@@ -879,15 +934,22 @@ describe('Execute: Handles inputs', () => {
879
934
} ) ;
880
935
} ) ;
881
936
882
- it ( 'when argument provided cannot be parsed ' , async ( ) => {
937
+ it ( 'not when argument cannot be coerced ' , async ( ) => {
883
938
const ast = parse ( `{
884
939
fieldWithDefaultArgumentValue(input: WRONG_TYPE)
885
940
}` ) ;
886
941
887
942
return expect ( await execute ( schema , ast ) ) . to . deep . equal ( {
888
943
data : {
889
- fieldWithDefaultArgumentValue : '"Hello World"'
890
- }
944
+ fieldWithDefaultArgumentValue : null
945
+ } ,
946
+ errors : [ {
947
+ message :
948
+ 'Argument "input" got invalid value WRONG_TYPE.\n' +
949
+ 'Expected type "String", found WRONG_TYPE.' ,
950
+ locations : [ { line : 2 , column : 46 } ] ,
951
+ path : [ 'fieldWithDefaultArgumentValue' ]
952
+ } ]
891
953
} ) ;
892
954
} ) ;
893
955
0 commit comments