Allow "null" to be passed in filters
And convert to Ruby's nil
Did some initial work here: https://github.com/richmolj/graphiti/tree/filter_nil
Though the work is pretty straightforward, there is a purpose to disallowing nils. Passing a nil can sometimes cause slow/expensive database queries, and it should probably be disabled by default. This means we probably need 2 options
filter :foo, allow_nil: trueself.filters_accept_nil_by_default = true (defaults to false`)
@wadetandy sound about right?
Makes sense and I agree that we should not change the defaults. If we're doing some nice things on behalf of nil, it might be a good idea to do the same for javascript's undefined, though I can also see this being a more common thing that is actual a desired filter. Maybe have a configurable list of "strings we coerce to nil" with sensible defaults?
I would recommend following the JSON spec that undefined is an invalid conversion to Ruby.
> JSON.parse("undefined")
#=> JSON::ParserError (416: unexpected token at 'undefined')
> JSON.parse("null")
#=> nil
Yeah, I agree with @zeisler - also makes sense because in Spraypaint, I would drop undefined and not send as part of the request, but null should turn into the string "null".
Maybe we'll move to a configurable whitelist at some point, but that seems good for now.
In general I would Be in favor of either allowing nil and undefined OR allowing neither, but I’m not going to get too worked up about any outcome here.