-
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
Improve enum compatibility #1153
Conversation
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. |
d80937d
to
31fb2da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! 🎊
I think this PR needs further review and deep analysis. I'm not sure the middleware approach is the optimal one to solve the compatibility with Graphene 2 |
26229d6
to
1d3525e
Compare
Looks great. Merging |
This reverts commit 81fff0f.
Hi @jkimbo |
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
This PR improves enum compatibility by allowing resolvers to return enums as well as their values and names. It also changes the input values for mutations to be the enum rather than the enum value.
Example:
Since this change is backwards incompatible by changing the way mutations with enum inputs work I've also added a compatibility middleware (We decided against adding a middleware because it was too complicated and probably wouldn't have worked properly anyway. Decided to go with documenting the change instead.enum_value_convertor_middleware
) that can be added so that mutations behave as they did. This should give people the ability to migrate their applications after upgrading to v3.TODO