Skip to content
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

fix: Add support for generated enums in mutation input #497

Merged

Conversation

cngai
Copy link
Contributor

@cngai cngai commented Mar 7, 2024

Description

If GENERATE_ENUMS_FROM_CHOICES is set to True, mutations with enum input values will resolve the input type as an enum. When the input is parsed, it tries to save the field as an enum instead of a string value, causing Django to throw a ValidationError "Value 'ExampleEnum.VALUE' is not a valid choice.". This PR addresses this issue by parsing the enum and returning the enum value.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Fix #491

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cngai - Here's my review!

General suggestions:

  • Consider adding more comprehensive tests to cover edge cases, especially where enum values might require further parsing or validation.
  • Review the handling of Enums in other parts of the codebase to ensure consistency with this new approach.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

strawberry_django/mutations/resolvers.py Show resolved Hide resolved
@cngai
Copy link
Contributor Author

cngai commented Mar 12, 2024

Hey @bellini666 - would you mind giving this PR a review when you get the chance? Really appreciate it!

@bellini666 bellini666 force-pushed the fix/generated_enums_in_mutations branch from 11068f1 to f624d12 Compare March 16, 2024 12:47
@bellini666 bellini666 changed the title FIX: Add support for generated enums in mutation input fix: Add support for generated enums in mutation input Mar 16, 2024
@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.98%. Comparing base (23c4126) to head (f624d12).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #497      +/-   ##
==========================================
+ Coverage   87.97%   87.98%   +0.01%     
==========================================
  Files          37       37              
  Lines        3184     3187       +3     
==========================================
+ Hits         2801     2804       +3     
  Misses        383      383              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry for taking some time to check this.

LGTM, thanks for this! :)

@bellini666 bellini666 merged commit 1324488 into strawberry-graphql:main Mar 16, 2024
50 checks passed
@cngai
Copy link
Contributor Author

cngai commented Mar 16, 2024

Thanks @bellini666 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum values in mutation input causes ValidationError
3 participants