-
Notifications
You must be signed in to change notification settings - Fork 181
Null value from non-required enum field raises exception #201
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'm experiencing the same issue. Please help <3 |
Also experiencing this issue I think. After upgrading from 2.0.0 to 2.1.0 an enum key with a null value no longer works as an argument.
Where Seems like this resolved issue from graphql-js might be related. |
I'm experiencing this issue as well. Is there a recommended way to let enum fields be import pytz
import graphene
from graphene_django.converter import convert_choice_name
from enum import Enum
OptionsEnum = Enum(value='TimezoneOptions',
names=[(convert_choice_name(tz), tz)
for tz in pytz.common_timezones])
TimezoneOptions = graphene.Enum.from_enum(
OptionsEnum, description=lambda tz: tz and tz.value)
def timezone_resolver(model, _):
tz = model.timezone
return TimezoneOptions.get(tz.zone if hasattr(tz, 'zone') else tz)
# Part of my UserNode, it's not everything
class UserNode(DjangoObjectType):
timezone = graphene.Field(TimezoneOptions,
resolver=timezone_resolver,
required=False) |
I'm curious if one of the maintainers could weigh in on this. We have a lot of places in our codebase where we'd like to have nullable enums, but if this isn't getting fixed we'll probably go another direction. |
@jarcoal: This repository is for v2 of graphql-core only which is not under active development any more. Current development in v3 has moved to https://github.com/graphql-python/graphql-core-next. |
@Cito thanks for the heads up, I'll start tracking graphene's progress on switching over to that. |
I've been searching for the underlying cause of the error in graphene-django that breaks Django choice fields when the value is blank: graphql-python/graphene-django#474 . This is a regression, new since graphql-core 2.1.
The validation for an enum value new in version 2.1 doesn't seem to take into account whether or not the field is allowed to have a null value before raising an exception.
From https://github.com/graphql-python/graphql-core/blob/fa4eeda36029680205e20059379e89189b946032/graphql/execution/executor.py#L605
Should this exception be the exception shouldn't be raised unconditionally? The graphql source has the same pattern in it but perhaps catches the error ... https://github.com/graphql/graphql-js/blob/master/src/execution/execute.js#L967
The text was updated successfully, but these errors were encountered: