-
-
Notifications
You must be signed in to change notification settings - Fork 545
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
Issues with strawberry.UNSET #2144
Comments
@ThirVondukr I think you need to mark the fields as optional as well: @strawberry.input
class StrawberryUnset:
a: Optional[int] = strawberry.UNSET
b: Optional[int] = strawberry.UNSET otherwise the GraphQL validation will complain 😊 |
@patrick91 I think there's a use case for a non-null optional field, but I don't know if graphql spec allows that 🤔 @strawberry.input
class BookUpdate:
title: str = strawberry.UNSET
published_at: Optional[datetime] = strawberry.UNSET This has benefit of checking all of the values for |
I wonder if that's something we can provide, or at least allow, the GraphQL spec doesn't allow it, so it would be something we do in our codebase, but I'm unsure how to do that :) |
Main issue (at least for me) is that implementing partial updates is kind of awkward |
@strawberry.input
class BookUpdate:
title: str = None
published_at: datetime | None = strawberry.UNSET
@strawberry.type
class Mutation:
async def book_update(
self,
id: strawberry.ID,
input: BookUpdate,
) -> BookType:
book = await fetch_book_somehow(id)
if input.title is None:
book.title = input.title
if input.published_at is strawberry.UNSET:
book.published_at = input.published_at
... |
FYI I think this proposal should still be implemented: #872 |
@jkimbo It seems that was the case ~10 months ago, it worked in my old project which used strawberry |
strawberry.UNSET doesn't make parameters optional
It's not possible to use
strawberry.UNSET
for optional parameters:Would fail because a and b are required.
Query to _service.sdl fails custom sentinel object is used in place of strawberry.UNSET:
System Information
Additional Context
Code Reference: https://gitlab.com/ThirVondukr/strawberry-info-warning/-/blob/unset/tests/test_error.py
Upvote & Fund
The text was updated successfully, but these errors were encountered: