-
Notifications
You must be signed in to change notification settings - Fork 822
General wrongness working with Enums #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
update: never mind, I got the existing syntax to work. I still think the code is overly-complicated and this syntax isn't that useful, but it works. The more I look at the code trying to resolve it, the more it looks like I'll want to completely break the existing syntax and replace it with something like this: from enum import Enum
import graphene
@graphene.enum
class Episode(Enum):
NEWHOPE = 4
EMPIRE = 5
JEDI = 6
LengthUnit = graphene.enum(ExistingPythonEnum) Which, while obviously much less cool than the existing syntax, it's not much less readable and makes the Graphene source much more readable. Thoughts? |
@avivey what was your solution for fixing introspection with default values? Both |
I didn't have one. |
That's basically the approach I've gone for too - it's just not ideal for clarity in some situations :/ |
Could you clarify what you did? I'm using graphene.Enum.from_enum() |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This works for me: from enum import Enum
import graphene
class NoValue(Enum):
def __repr__(self):
return '<%s.%s>' % (self.__class__.__name__, self.name)
class Color(NoValue):
RED = 'stop'
GREEN = 'go'
BLUE = 'too fast!' Now you can: print(Color.GREEN)
>>> <Color.GREEN>
print(Color.GREEN.value)
>>> 'go' In @graphene.Enum.from_enum
class ColorOptions(NoValue):
RED = 'stop'
GREEN = 'go'
BLUE = 'too fast!' |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
How do I get an enum argument from a query? I still get the value (str or int). |
This is for graphene 2.1.3.
There are a bunch of issues working with enums, here are two that bite me right now:
default_value
, we need to explicitly add.name
or.value
, else introspection breaks (see commented out code)..value
, the schema generated is wrong (See test 1 below)..name
, the schema is correct, but the argument passed to the function is a string that doesn't match any value (See test 1 and 2).Test code:
The text was updated successfully, but these errors were encountered: