You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it is a common practice in strawberry that when you'r data layer have
an optional field i.e
classPerson:
name: strphone: str|None=None
and you want to update it you'd use UNSET in the mutation
in order to check whether this field provided by the client or not like so:
@strawberry.inputclassUpdatePersonInput:
id: strawberry.IDname: str|Nonephone: str|None=UNSET@strawberry.mutationdefupdate_person(input: UpdatePersonInput) ->Person:
inst=service.get_person(input.id)
ifname:=input.name:
inst.name=nameifinput.phoneisnotUNSET:
inst.phone=input.phone# ❌ not type safeservice.save(inst)
Note that this is not an optimization rather a business requirement.
if the user wants to nullify the phone it won't be possible other wise
OTOH you might nullify the phone unintentionally.
This approach can cause lots of bugs since you need to remember that you have
used UNSET and to handle this correspondingly.
Since strawberry claims to
Strawberry leverages Python type hints to provide a great developer experience while creating GraphQL Libraries.
it is only natural for us to provide a typesafe way to mitigate this.
Currently if you want to know if a field was provided
Backward compat
UNSET can remain as is for existing codebases. Option would be handled separately.
which Option library should we use?
The sad truth is that there are no well-maintained libs in the ecosystem.
Never the less it is not hard to maintain something just for strawberry since the implementation
is rather straight forward and not much features are needed. we can fork either
Preface
it is a common practice in strawberry that when you'r data layer have
an optional field i.e
and you want to update it you'd use
UNSET
in the mutationin order to check whether this field provided by the client or not like so:
Note that this is not an optimization rather a business requirement.
if the user wants to nullify the phone it won't be possible other wise
OTOH you might nullify the phone unintentionally.
This approach can cause lots of bugs since you need to remember that you have
used
UNSET
and to handle this correspondingly.Since strawberry claims to
it is only natural for us to provide a typesafe way to mitigate this.
Proposal
The
Option
type.Currently if you want to know if a field was provided
Backward compat
UNSET
can remain as is for existing codebases.Option
would be handled separately.which
Option
library should we use?The sad truth is that there are no well-maintained libs in the ecosystem.
Never the less it is not hard to maintain something just for strawberry since the implementation
is rather straight forward and not much features are needed. we can fork either
and just forget about it.
Another option would be
then strawberry could use that and you could use whatever you want.
The text was updated successfully, but these errors were encountered: