Commit 02d5054c authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Mike Jang

Add how to define GraphQL enum from Rails enum

parent 92cd5ab3
...@@ -486,6 +486,28 @@ end ...@@ -486,6 +486,28 @@ end
Enum values can be deprecated using the Enum values can be deprecated using the
[`deprecated` keyword](#deprecating-fields-and-enum-values). [`deprecated` keyword](#deprecating-fields-and-enum-values).
### Defining GraphQL enums dynamically from Rails enums
If your GraphQL enum is backed by a [Rails enum](creating_enums.md), then consider
using the Rails enum to dynamically define the GraphQL enum values. Doing so
binds the GraphQL enum values to the Rails enum definition, so if values are
ever added to the Rails enum then the GraphQL enum automatically reflects the change.
Example:
```ruby
module Types
class IssuableSeverityEnum < BaseEnum
graphql_name 'IssuableSeverity'
description 'Incident severity'
::IssuableSeverity.severities.keys.each do |severity|
value severity.upcase, value: severity, description: "#{severity.titleize} severity"
end
end
end
```
## JSON ## JSON
When data to be returned by GraphQL is stored as When data to be returned by GraphQL is stored as
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment