How to define an Enum Input in mutation?
See original GitHub issueIn models.py, I defined a python Enum class:
class EmployeeKind(PyEnum):
contractor = 1
fulltime = 2
parttime = 3
and in schema.py, I defined a mutation class:
class UpdateEmployee(graphene.Mutation):
class Arguments:
id = graphene.ID(required=True)
name = graphene.String()
department_id = graphene.ID()
role_id = graphene.ID()
kind = graphene.Enum.from_enum(EmployeeKind)
...
But when running the script, it shows an error:
Traceback (most recent call last):
File "....../gqlsql/./app.py", line 5, in <module>
from schema import schema
File "....../gqlsql/schema.py", line 181, in <module>
class Mutation(graphene.ObjectType):
File "....../gqlsql/schema.py", line 183, in Mutation
update_employee = UpdateEmployee.Field()
File "....../gqlsql/.venv/lib/python3.9/site-packages/graphene/types/mutation.py", line 139, in Field
return Field(
File "....../gqlsql/.venv/lib/python3.9/site-packages/graphene/types/field.py", line 103, in __init__
self.args = to_arguments(args or OrderedDict(), extra_args)
File "....../gqlsql/.venv/lib/python3.9/site-packages/graphene/types/argument.py", line 104, in to_arguments
raise ValueError('Unknown argument "{}".'.format(default_name))
ValueError: Unknown argument "kind".
What does this error mean? Why?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
GraphQL - Passing an enum value directly to a mutation as ...
use the enum variable name as defined in the mutation and send it to Graphql, like I have used gender As $gender: Gender!...
Read more >How to use GraphQL enum and its best practices
The enum class allows us to map enum values to internal values represented by integers (or different strings etc.). By defining enumerated ...
Read more >The enum type | Side Quest: Intermediate Schema Design
An enum is a GraphQL schema type that represents a predefined list of possible values. For example, in Airlock, listings can be a...
Read more >How to use GraphQL enum and its best practices
In GraphQL, Enum type can be used as input and output type. Enums are a great way to add additional validation constraints. We...
Read more >What you need to know about GraphQL enums
How to use enums ... GraphQL enums can be defined using the enum keyword. ... According to the official specification, you should name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
graphene.Enum.from_enum(EmployeeKind)
returns a type object which you then need to call.This:
is essentially a dynamic form of:
except the first is based on an existing Python Enum.
Example:
Thanks @shaozi!
You’re right about the Enums. Graphene v3 has better Enum support, resolvers will receive the Enum member directly rather than the value—as you suggest.
Graphene v3 is still in beta though, Graphene-SQLAlchemy is using v2.