-
-
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
Add pydantic conversion compatibility with specialized list class #2909
Add pydantic conversion compatibility with specialized list class #2909
Conversation
Thanks for adding the Here's a preview of the changelog: Enhancements:
This enhancement enables the usage of constrained lists as class types and allows the creation of specialized lists. The following example demonstrates this feature: import strawberry
from pydantic import BaseModel, ConstrainedList
class FriendList(ConstrainedList):
min_items = 1
class UserModel(BaseModel):
age: int
friend_names: FriendList[str]
@strawberry.experimental.pydantic.type(UserModel)
class User:
age: strawberry.auto
friend_names: strawberry.auto Here's the preview release card for twitter: Here's the tweet text:
|
e820f9a
to
a1cab5c
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2909 +/- ##
==========================================
- Coverage 96.53% 96.39% -0.15%
==========================================
Files 468 468
Lines 29112 29169 +57
Branches 3582 3589 +7
==========================================
+ Hits 28104 28118 +14
- Misses 827 863 +36
- Partials 181 188 +7 |
sorry i missed this, this seems quite cool and i'll check it out |
3059020
to
d7bc31d
Compare
d7bc31d
to
ee2c43a
Compare
CodSpeed Performance ReportMerging #2909 will not alter performanceComparing Summary
|
08139ba
to
0787a32
Compare
@tjeerddie thanks for keeping this up to date, I'll take a look at it this week |
0787a32
to
0272a25
Compare
- Modified `StrawberryAnnotation._is_list` to check if the `annotation` extends from the `list` type, enabling it to be considered a list. - in `StrawberryAnnotation` Moved the `_is_list` check before the `_is_generic` check in `resolve` to avoid `unsupported` error in `_is_generic` before it checked `_is_list`.
0272a25
to
e910059
Compare
…rawberry-graphql#2909) * Add tests for pydantic conversion for contrained list * Add pydantic conversion compatibility with specialized list class - Modified `StrawberryAnnotation._is_list` to check if the `annotation` extends from the `list` type, enabling it to be considered a list. - in `StrawberryAnnotation` Moved the `_is_list` check before the `_is_generic` check in `resolve` to avoid `unsupported` error in `_is_generic` before it checked `_is_list`. * Add release file --------- Co-authored-by: Tjeerd.Verschragen <[email protected]>
Description
_is_list
check before the_is_generic
check inStrawberryAnnotation.resolve
, so it does not get stuck onValueError: Not supported type
and first checks if it is a list.StrawberryAnnotation._is_list
to check if theannotation
extends from list and can be considered a list.Types of Changes
Issues Fixed or Closed by This PR
Checklist