-
Notifications
You must be signed in to change notification settings - Fork 181
Missing return in GraphQLEnumType.serialize #199
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
I meant if we initialize the enumeration by native Enum, then serializes function returns None instead members name. for example: import collections
from graphql.pyutils.compat import Enum as PyEnum
from graphql.type.definition import GraphQLEnumType, GraphQLEnumValue
class Color(PyEnum):
RED = 'RED'
GREEN = 'GREEN'
BLUE = 'BLUE'
# init as Enum members
enum_type = GraphQLEnumType('Color', values={
'RED': GraphQLEnumValue(Color.RED),
'GREEN': GraphQLEnumValue(Color.GREEN),
'BLUE': GraphQLEnumValue(Color.BLUE)
})
print(enum_type.serialize(Color.RED)) # None
print(enum_type.serialize(Color.GREEN)) # None
print(enum_type.serialize(Color.BLUE)) # None
# correct serialize method
def serialize(self, value):
# type: (Union[str, PyEnum]) -> Optional[str]
if isinstance(value, (collections.Hashable, PyEnum)):
enum_value = self._value_lookup.get(value)
if enum_value:
return enum_value.name
return None
GraphQLEnumType.serialize = serialize
print(enum_type.serialize(Color.RED)) # RED
print(enum_type.serialize(Color.GREEN)) # GREEN
print(enum_type.serialize(Color.BLUE)) # BLUE |
This PR #198 solves this issue |
Any news on this? It breaks using standard |
Has been merged now, will be in next patch release. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Guess there must be a return for PyEnum type
https://github.com/graphql-python/graphql-core/blob/02605b1adce7b287fa9ee6beacd735882954159a/graphql/type/definition.py#L518-L528
The text was updated successfully, but these errors were encountered: