graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

Allow "null" to be passed in filters

Open richmolj opened this issue 6 years ago • 5 comments

And convert to Ruby's nil

richmolj avatar May 15 '19 12:05 richmolj

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: true
  • self.filters_accept_nil_by_default = true (defaults to false`)

@wadetandy sound about right?

richmolj avatar May 15 '19 12:05 richmolj

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?

wadetandy avatar May 15 '19 14:05 wadetandy

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

zeisler avatar May 15 '19 18:05 zeisler

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.

richmolj avatar May 15 '19 19:05 richmolj

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.

wadetandy avatar May 15 '19 20:05 wadetandy