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
Uh oh!
There was an error while loading. Please reload this page.
-
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 handlenullthe same way I'd handleundefined, I would've had to update my interfaces and functions in my business logic to allownullfor all types that also allowedundefined.To save myself all that work, I found a great SO post that includes a recursive mapper from
nulltoundefined. The code is as follows:Now, on all my Pothos resolvers, I wrap the args in this
nullsToUndefinedfunction, 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
nullablecalledundefinable. Then,nullablewould only specify thatnullis allowed, not necessarily bothnullandundefined, andundefinablewould only specify thatundefinedis allowed, not necessarily bothnullandundefined. But as an intermediate solution, using a wrapper like this works well!Beta Was this translation helpful? Give feedback.
All reactions