-
-
Notifications
You must be signed in to change notification settings - Fork 535
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 support for implicit UNSET as a type annotation #872
Comments
I wonder if it's simpler to just make Note: |
I think it could, it does require you to explicitly set the default value to |
Also what should happen if you define |
I think that should be pretty easy to solve with a custom scalar? |
From a typing perspective, that is a valid value but it's impossible to reach there since this should be emitted into a When using the union method, I currently get the following error:
|
@sarahhenkens we (well @jkimbo :D) are going to work on this as discussed in our monthly meeting 😊 #986 |
A minor fix to the annotation parser to allow for stricter type annotation for optional and unsettable field args #1467 |
This is a major flaw in the libary IMO. My current workaround is to use
The type checker understands that if you provide |
Currently, we need to set the default value to
strawberry.arguments.UNSET
to support optional arguments. This object has theAny
annotation which hides itself from type checkers.Example:
MyPy will consider
id
to be aUnion[ID, None]
while in reality, it's aUnion[ID, None, _Unset]
. This results in potential bugs in code where the type-checker would catch it.For example, the following snippet will raise an error without a type checker catching it:
Proposal
My proposal is to introduce a new type alias as a first-class citizen in the Strawberry type system:
And its usage in resolvers:
UNSET
to its value if it was not included in the requestJust optional
This allows us to also provide the option for resolvers to define a simpler default behavior when we only care about
strawberry.ID
vsNone
:None
to its value if it was not included in the requestUpvote & Fund
The text was updated successfully, but these errors were encountered: