@@ -55,7 +55,7 @@ class Thing < GraphQL::Schema::Object
55
55
end
56
56
57
57
it "validates arguments" do
58
- err = assert_raises ArgumentError do
58
+ err = assert_raises GraphQL :: Schema :: Directive :: InvalidArgumentError do
59
59
GraphQL ::Schema ::Field . from_options (
60
60
name : :something ,
61
61
type : String ,
@@ -65,9 +65,9 @@ class Thing < GraphQL::Schema::Object
65
65
)
66
66
end
67
67
68
- assert_equal "@secret.topSecret is required, but no value was given " , err . message
68
+ assert_equal "@secret.topSecret on Thing.something is invalid (nil): Expected value to not be null " , err . message
69
69
70
- err2 = assert_raises ArgumentError do
70
+ err2 = assert_raises GraphQL :: Schema :: Directive :: InvalidArgumentError do
71
71
GraphQL ::Schema ::Field . from_options (
72
72
name : :something ,
73
73
type : String ,
@@ -77,7 +77,7 @@ class Thing < GraphQL::Schema::Object
77
77
)
78
78
end
79
79
80
- assert_equal "@secret.topSecret is required, but no value was given " , err2 . message
80
+ assert_equal "@secret.topSecret on Thing.something is invalid (12.5): Could not coerce value 12.5 to Boolean " , err2 . message
81
81
end
82
82
83
83
describe 'repeatable directives' do
@@ -400,4 +400,38 @@ def numbers
400
400
enum_value = schema . get_type ( "Stuff" ) . values [ "THING" ]
401
401
assert_equal [ [ "tag" , { name : "t7" } ] , [ "tag" , { name : "t8" } ] ] , enum_value . directives . map { |dir | [ dir . graphql_name , dir . arguments . to_h ] }
402
402
end
403
+
404
+ describe "Validating schema directives" do
405
+ def build_sdl ( size :)
406
+ <<~GRAPHQL
407
+ directive @tshirt(size: Size!) on INTERFACE | OBJECT
408
+
409
+ type MyType @tshirt(size: #{ size } ) {
410
+ color: String
411
+ }
412
+
413
+ type Query {
414
+ myType: MyType
415
+ }
416
+
417
+ enum Size {
418
+ LARGE
419
+ MEDIUM
420
+ SMALL
421
+ }
422
+ GRAPHQL
423
+ end
424
+
425
+ it "Raises a nice error for invalid enum values" do
426
+ valid_sdl = build_sdl ( size : "MEDIUM" )
427
+ assert_equal valid_sdl , GraphQL ::Schema . from_definition ( valid_sdl ) . to_definition
428
+
429
+ typo_sdl = build_sdl ( size : "BLAH" )
430
+ err = assert_raises GraphQL ::Schema ::Directive ::InvalidArgumentError do
431
+ GraphQL ::Schema . from_definition ( typo_sdl )
432
+ end
433
+ expected_msg = '@tshirt.size on MyType is invalid ("BLAH"): Expected "BLAH" to be one of: LARGE, MEDIUM, SMALL'
434
+ assert_equal expected_msg , err . message
435
+ end
436
+ end
403
437
end
0 commit comments