-
-
Notifications
You must be signed in to change notification settings - Fork 536
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 Pydantic Unions #1231
Fix Pydantic Unions #1231
Conversation
…ma_fix_unions_pydantic # Conflicts: # tests/experimental/pydantic/test_conversion.py
Thanks for adding the Here's a preview of the changelog: Fixes a bug in the Pydantic conversion code around Here's the preview release card for twitter: Here's the tweet text:
|
Codecov Report
@@ Coverage Diff @@
## main #1231 +/- ##
==========================================
- Coverage 97.58% 97.56% -0.03%
==========================================
Files 88 88
Lines 3360 3369 +9
Branches 489 493 +4
==========================================
+ Hits 3279 3287 +8
Misses 45 45
- Partials 36 37 +1 |
@Matt343 thanks! I'll try to review this over the weekend ^^ |
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.
Looks good! I've only added a note, but it is nothing to worry about for now, we'll deal with it when we finalise some refactoring and when we tackle this issue: #1192
@@ -144,6 +144,7 @@ def wrap(cls): | |||
) | |||
|
|||
model._strawberry_type = cls # type: ignore | |||
cls._pydantic_type = model # type: ignore |
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.
this is a patter we want to move away from :)
I think we can keep this for now though, we still need to do some refactoring anyway ^^
Description
In order to convert Union types from Pydantic models into Strawberry models, we need to check which branch of the Union we have and proceed with the conversion according to that type definition. I had to add a
_pydantic_type
field to ourStrawberryType
instances that are created through the converter so that we can get a reference to the original type of each branch for comparison. This seems a little hacky, but I couldn't think of a better way.This fix only works for Unions of object types, but that should be fine as GraphQL doesn't support other types of unions.
Types of Changes
Issues Fixed or Closed by This PR
Checklist