forked from strawberry-graphql/strawberry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pydantic conversion compatibility with specialized list class (st…
…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]>
- Loading branch information
Showing
4 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Release type: patch | ||
|
||
Enhancements: | ||
- Improved pydantic conversion compatibility with specialized list classes. | ||
- 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`. | ||
|
||
This enhancement enables the usage of constrained lists as class types and allows the creation of specialized lists. The following example demonstrates this feature: | ||
|
||
```python | ||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters