-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
prototype: pydantic object type extension #2612
base: main
Are you sure you want to change the base?
prototype: pydantic object type extension #2612
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2612 +/- ##
==========================================
- Coverage 96.30% 95.50% -0.80%
==========================================
Files 184 186 +2
Lines 7546 7661 +115
Branches 1385 1407 +22
==========================================
+ Hits 7267 7317 +50
- Misses 178 238 +60
- Partials 101 106 +5 |
@@ -193,6 +200,7 @@ def type( | |||
is_interface: bool = False, | |||
description: Optional[str] = None, | |||
directives: Optional[Sequence[object]] = (), | |||
extensions: Optional[List[TypeExtension]] = None, |
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.
lame nitpick -> should at least follow directies and have a default of empty sequence. e.g.
directives: Optional[Sequence[object]] = (),
extensions: Optional[Sequence[TypeExtension]] = (),
though idk why we even needed the None case, it could just be
extensions: Sequence[TypeExtension]] = (),
@@ -46,6 +48,8 @@ class TypeDefinition(StrawberryType): | |||
) | |||
|
|||
def __post_init__(self): | |||
for extension in self.extensions: | |||
extension.apply(self) |
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.
cool stuff
looks great to me as a prototype for exploration. I guess something to think about is how we'll retrieve some static information of the transformation. E.g. how do we get our static typecheckers to know that |
assert field1.metadata["admin_only"] | ||
|
||
assert field2.python_name == "public" | ||
assert not field2.metadata |
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.
oh, i think you'll need some tests calling from pydantic
or to_pydantic
seems like PydanticTypeExtension
doesn't define it too?
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.
Yes, these were just the basic tests to see if the general idea works. Will add more soon 🙂
PydanticTypeExtension should also set the from and to methods, but type checking is indeed an issue
Good point. Maybe we could make all of these model dataclasses extend @strawberry.type(extensions=[PydanticTypeExtension(model=User)])
class UserType(StrawberryTypeFromPydantic):
age: strawberry.auto
password: strawberry.auto The advantage with this is that IDEs will automatically suggest |
Prototype for #2605