File tree Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,21 @@ module GraphQL
55
55
# args[:favoriteLanguage] # => :rb
56
56
# }
57
57
#
58
+ # @example Enum whose values are different in ActiveRecord-land
59
+ # class Language < ActiveRecord::BaseType
60
+ # enum language: {
61
+ # rb: 0
62
+ # }
63
+ # end
64
+ #
65
+ # # Now enum type should be defined as
66
+ # GraphQL::EnumType.define do
67
+ # # ...
68
+ # # use the `value:` keyword:
69
+ # value("RUBY", "Lisp? Smalltalk?", value: 'rb')
70
+ # end
71
+ #
72
+
58
73
class EnumType < GraphQL ::BaseType
59
74
accepts_definitions :values , value : GraphQL ::Define ::AssignEnumValue
60
75
Original file line number Diff line number Diff line change 15
15
it "coerces result values to value's value" do
16
16
assert_equal ( "YAK" , enum . coerce_result ( "YAK" ) )
17
17
assert_equal ( "COW" , enum . coerce_result ( 1 ) )
18
+ assert_equal ( "REINDEER" , enum . coerce_result ( 'reindeer' ) )
19
+ assert_equal ( "DONKEY" , enum . coerce_result ( :donkey ) )
18
20
end
19
21
20
22
it "raises when a result value can't be coerced" do
Original file line number Diff line number Diff line change 23
23
] }
24
24
25
25
let ( :dairy_animals ) { [
26
- { "name" => "COW" , "isDeprecated" => false } ,
27
- { "name" => "GOAT" , "isDeprecated" => false } ,
28
- { "name" => "SHEEP" , "isDeprecated" => false } ,
26
+ { "name" => "COW" , "isDeprecated" => false } ,
27
+ { "name" => "DONKEY" , "isDeprecated" => false } ,
28
+ { "name" => "GOAT" , "isDeprecated" => false } ,
29
+ { "name" => "REINDEER" , "isDeprecated" => false } ,
30
+ { "name" => "SHEEP" , "isDeprecated" => false } ,
29
31
] }
30
32
it "exposes metadata about types" do
31
33
expected = { "data" => {
Original file line number Diff line number Diff line change @@ -33,10 +33,12 @@ class NoSuchDairyError < StandardError; end
33
33
DairyAnimalEnum = GraphQL ::EnumType . define do
34
34
name "DairyAnimal"
35
35
description "An animal which can yield milk"
36
- value ( "COW" , "Animal with black and white spots" , value : 1 )
37
- value ( "GOAT" , "Animal with horns" )
38
- value ( "SHEEP" , "Animal with wool" )
39
- value ( "YAK" , "Animal with long hair" , deprecation_reason : "Out of fashion" )
36
+ value ( "COW" , "Animal with black and white spots" , value : 1 )
37
+ value ( "DONKEY" , "Animal with fur" , value : :donkey )
38
+ value ( "GOAT" , "Animal with horns" )
39
+ value ( "REINDEER" , "Animal with horns" , value : 'reindeer' )
40
+ value ( "SHEEP" , "Animal with wool" )
41
+ value ( "YAK" , "Animal with long hair" , deprecation_reason : "Out of fashion" )
40
42
end
41
43
42
44
CheeseType = GraphQL ::ObjectType . define do
You can’t perform that action at this time.
0 commit comments