graphene3: enum doesn't resolve to value
See original GitHub issueUsing enums as inputFields leads to errors
SalutationEnum = graphene.Enum('SalutationEnum', [('Man', 0), ('Woman', 1)])
class MyModel(Model):
salutation = models.IntegerField()
class SomeInput(graphene.InputObjectType):
salutation = SalutationEnum(required=True)
class MyMutation(graphene.Mutation):
...
class Arguments:
input = SomeInput(required=True)
...
mutate(self, info, input):
...
myModel.salutation = input.salutation
myModel.save()
leads to
"message": "Field 'salutation' expected a number but got <SalutationEnum.Man: 0>.",
I think the problem is, that SalutationEnum is not resolved to its value (this worked in graphene 2.x) but resolved to a SalutationEnum
salutation: SalutationEnum{
name: 'Man'
value: 0
}
This code would work:
myModel.salutation = input.salutation.value
myModel.save()
But I don’t think it is intended to call value on each enum?
Edit: Just found #1151 - looks like this is intended??
graphene: 3.0.0b5
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Graphene: Enum argument doesn't seem to work
The issue here is that we can assign an arbitrary value for each enum value, but this value is only used internally by...
Read more >Enums - Graphene-Python
An Enum is a special GraphQL type that represents a set of symbolic names (members) bound to unique, constant values. Definition¶. You can...
Read more >How to use the graphene.Enum function in graphene - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... v.value) for v in type.choices))...
Read more >Graphene Documentation
It's possible to add a description to an enum value, for that the ... Enum internally (or a backport if that's not available)...
Read more >Graphene Documentation - Read the Docs
The first parameter of a resolver method (parent) is the value object returned from the resolver of the parent field. If there is...
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
Just tried your example and I can confirm this is working
Just debuged deep into this process and found that I wrote a wrong value into the DB when I tried around with the enums.
That was really confusing because the database value was
MemberRoleEnum.Administrator
and notadmin
.Btw. great work @jkimbo & contributors - looking foward the 3.0 release
Ah ok I see. You can also check if the value is an enum before trying to access
.value
.Anyway closing this issue.