If you're running into errors with nullable Pothos types allowing both null and undefined, try this! #889
colinparsonscom
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Random note in case anyone runs into the same issue I was running into a little while ago. I was specifying certain fields as nullable in my Pothos builder, but what I really wanted was for these fields to allow
undefined
(but notnull
). To handlenull
the same way I'd handleundefined
, I would've had to update my interfaces and functions in my business logic to allownull
for all types that also allowedundefined
.To save myself all that work, I found a great SO post that includes a recursive mapper from
null
toundefined
. The code is as follows:Now, on all my Pothos resolvers, I wrap the args in this
nullsToUndefined
function, like so:It saves a lot of work and messiness in my business logic; would recommend!
Posting this as an idea because it'd be nice to not have to use this wrapper in the first place, and have an additional option analogous to
nullable
calledundefinable
. Then,nullable
would only specify thatnull
is allowed, not necessarily bothnull
andundefined
, andundefinable
would only specify thatundefined
is allowed, not necessarily bothnull
andundefined
. But as an intermediate solution, using a wrapper like this works well!Beta Was this translation helpful? Give feedback.
All reactions