Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
02d5054c
Commit
02d5054c
authored
Oct 08, 2020
by
Luke Duncalfe
Committed by
Mike Jang
Oct 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add how to define GraphQL enum from Rails enum
parent
92cd5ab3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
doc/development/api_graphql_styleguide.md
doc/development/api_graphql_styleguide.md
+22
-0
No files found.
doc/development/api_graphql_styleguide.md
View file @
02d5054c
...
...
@@ -486,6 +486,28 @@ end
Enum values can be deprecated using the
[
`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
When data to be returned by GraphQL is stored as
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment