-
Notifications
You must be signed in to change notification settings - Fork 828
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
graphene3: enum doesn't resolve to value #1277
Comments
@Speedy1991 What does your query look like? |
variables (typescriped with codegen): Codegen generated type:
typescript generated with: |
Ah ok @Speedy1991 this is the expected behaviour. Starting in Graphene 3 enum inputs to mutations are the enum member rather than the enum value (which was the case in Graphene 2). See #1153 To get the enum value you will have to access Does that make sense? |
Yea that makes sense. E.g. Django.:
My workaround is now:
|
Ah ok I see. You can also check if the value is an enum before trying to access Anyway closing this issue. |
Hey @jkimbo
Query MemberType with Leads to
That worked back in graphene2. Any idea whats going wrong here? Running |
@Speedy1991 I can't reproduce that issue. Running this works for me: def test_enum_issue_1277():
MemberRoleEnum = Enum(
"MemberRoleEnum", [("Vertrieb", "staff"), ("Administrator", "admin")]
)
class Query(ObjectType):
role = MemberRoleEnum(required=False)
def resolve_role(self, info):
return self["role"] # 'admin'
schema = Schema(Query)
result = schema.execute("{ role }", root={"role": "admin"})
assert not result.errors
assert result.data == {
"role": "Administrator",
} |
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 Btw. great work @jkimbo & contributors - looking foward the 3.0 release |
@jkimbo There are a lot of places where I am using MyGeneratedEnum = MyObjectType._meta.fields["my_enum_field"].type
class MyMutation(graphene.Mutation):
class Meta:
enum_input = graphene.List(MyGeneratedEnum) this will give me a list of the enums, not a list of the values, which forces me add extra code that was previously done automatically. Do I now have to transform the list of enums into a list of values for every case or is there a better alternative? |
I also upgrading to v3 and running into a similar challenge as @DenisseRR. By default when I inspect the schema type that is auto-generated for the enum Char fields, it does use the same type as Any ideas or instructions on what to do? |
might be useful because Graphene 3 has changed from using enum values to enums, for example: ```python class TestEnum(graphene.Enum): FIRST = 'first' SECOND = 'second' ``` would've been serialized previously using the enum values, i.e. 'first' and 'second'. But with Graphene 3 they are serialized as 'TestEnum.FIRST' and 'TestEnum.SECOND'. This breaks functionality as parts of the codebase are expecting the enum values as per Graphene 2. Related https://github.com/graphql-python/graphene issues & PRs: - "Improve enum compatibility" PR: - graphql-python/graphene#1153 - "graphene3: enum doesn't resolve to value" issue: - graphql-python/graphene#1277 - "I would like my enum input values to be the enum instance instead of the enum values" issue: - graphql-python/graphene#1151 refs KK-1108
might be useful because Graphene 3 has changed from using enum values to enums, for example: ```python class TestEnum(graphene.Enum): FIRST = 'first' SECOND = 'second' ``` would've been serialized previously using the enum values, i.e. 'first' and 'second'. But with Graphene 3 they are serialized as 'TestEnum.FIRST' and 'TestEnum.SECOND'. This breaks functionality as parts of the codebase are expecting the enum values as per Graphene 2. Related https://github.com/graphql-python/graphene issues & PRs: - "Improve enum compatibility" PR: - graphql-python/graphene#1153 - "graphene3: enum doesn't resolve to value" issue: - graphql-python/graphene#1277 - "I would like my enum input values to be the enum instance instead of the enum values" issue: - graphql-python/graphene#1151 refs KK-1108
might be useful because Graphene 3 has changed from using enum values to enums, for example: ```python class TestEnum(graphene.Enum): FIRST = 'first' SECOND = 'second' ``` would've been serialized previously using the enum values, i.e. 'first' and 'second'. But with Graphene 3 they are serialized as 'TestEnum.FIRST' and 'TestEnum.SECOND'. This breaks functionality as parts of the codebase are expecting the enum values as per Graphene 2. Related https://github.com/graphql-python/graphene issues & PRs: - "Improve enum compatibility" PR: - graphql-python/graphene#1153 - "graphene3: enum doesn't resolve to value" issue: - graphql-python/graphene#1277 - "I would like my enum input values to be the enum instance instead of the enum values" issue: - graphql-python/graphene#1151 refs KK-1108
might be useful because Graphene 3 has changed from using enum values to enums, for example: ```python class TestEnum(graphene.Enum): FIRST = 'first' SECOND = 'second' ``` would've been serialized previously using the enum values, i.e. 'first' and 'second'. But with Graphene 3 they are serialized as 'TestEnum.FIRST' and 'TestEnum.SECOND'. This breaks functionality as parts of the codebase are expecting the enum values as per Graphene 2. Related https://github.com/graphql-python/graphene issues & PRs: - "Improve enum compatibility" PR: - graphql-python/graphene#1153 - "graphene3: enum doesn't resolve to value" issue: - graphql-python/graphene#1277 - "I would like my enum input values to be the enum instance instead of the enum values" issue: - graphql-python/graphene#1151 refs KK-1108
Done: - Upgrade all dependencies - Upgrade postgresql from v10 to v13 (v13 is used in production) - Use ruff instead of black/isort/flake8, remove noqa's, reformat - Use pyproject.toml instead of setup.cfg Background for @map_enums_to_values_in_kwargs decorator: Graphene 3 changed from using enum values to enums, for example: ```python class TestEnum(graphene.Enum): FIRST = 'first' SECOND = 'second' ``` would've been serialized previously using the enum values, i.e. 'first' and 'second'. But with Graphene 3 they are serialized as 'TestEnum.FIRST' and 'TestEnum.SECOND'. This broke functionality as parts of the codebase were expecting the enum values as per Graphene 2. Forced backwards compatibility by forcefully mapping enums to their values. Related https://github.com/graphql-python/graphene issues & PRs: - "Improve enum compatibility" PR: - graphql-python/graphene#1153 - "graphene3: enum doesn't resolve to value" issue: - graphql-python/graphene#1277 - "I would like my enum input values to be the enum instance instead of the enum values" issue: - graphql-python/graphene#1151 See https://github.com/graphql-python/graphene/wiki/v3-release-notes for Graphene v3's breaking changes, refs PT-1730
Done: - Upgrade all dependencies - Upgrade postgresql from v10 to v13 (v13 is used in production) - Use ruff instead of black/isort/flake8, remove noqa's, reformat - Use pyproject.toml instead of setup.cfg Background for @map_enums_to_values_in_kwargs decorator: Graphene 3 changed from using enum values to enums, for example: ```python class TestEnum(graphene.Enum): FIRST = 'first' SECOND = 'second' ``` would've been serialized previously using the enum values, i.e. 'first' and 'second'. But with Graphene 3 they are serialized as 'TestEnum.FIRST' and 'TestEnum.SECOND'. This broke functionality as parts of the codebase were expecting the enum values as per Graphene 2. Forced backwards compatibility by forcefully mapping enums to their values. Related https://github.com/graphql-python/graphene issues & PRs: - "Improve enum compatibility" PR: - graphql-python/graphene#1153 - "graphene3: enum doesn't resolve to value" issue: - graphql-python/graphene#1277 - "I would like my enum input values to be the enum instance instead of the enum values" issue: - graphql-python/graphene#1151 See https://github.com/graphql-python/graphene/wiki/v3-release-notes for Graphene v3's breaking changes, refs PT-1730
Using enums as inputFields leads to errors
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
This code would work:
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
The text was updated successfully, but these errors were encountered: