Skip to content

Commit d0c5d6d

Browse files
authored
Merge pull request rmosolgo#358 from zyixc/v1.0.0
Change documentation enum_type to include ActiveRecord::Base
2 parents 6aa7949 + c7e3fe8 commit d0c5d6d

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

lib/graphql/enum_type.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ module GraphQL
5555
# args[:favoriteLanguage] # => :rb
5656
# }
5757
#
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+
5873
class EnumType < GraphQL::BaseType
5974
accepts_definitions :values, value: GraphQL::Define::AssignEnumValue
6075

spec/graphql/enum_type_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
it "coerces result values to value's value" do
1616
assert_equal("YAK", enum.coerce_result("YAK"))
1717
assert_equal("COW", enum.coerce_result(1))
18+
assert_equal("REINDEER", enum.coerce_result('reindeer'))
19+
assert_equal("DONKEY", enum.coerce_result(:donkey))
1820
end
1921

2022
it "raises when a result value can't be coerced" do

spec/graphql/introspection/type_type_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
]}
2424

2525
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 },
2931
]}
3032
it "exposes metadata about types" do
3133
expected = {"data"=> {

spec/support/dairy_app.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ class NoSuchDairyError < StandardError; end
3333
DairyAnimalEnum = GraphQL::EnumType.define do
3434
name "DairyAnimal"
3535
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")
4042
end
4143

4244
CheeseType = GraphQL::ObjectType.define do

0 commit comments

Comments
 (0)