From e212a609b68f78b85de3ed8a3e19f5834b5eec78 Mon Sep 17 00:00:00 2001 From: Dustin Zeisler Date: Wed, 12 Jun 2019 12:11:28 -0700 Subject: [PATCH] \Allow "null" to be passed in filters Docs for PR https://github.com/graphiti-api/graphiti/pull/158 --- _config.yml | 2 +- guides/concepts/resources.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 150129e..0aca72c 100644 --- a/_config.yml +++ b/_config.yml @@ -32,7 +32,7 @@ exclude: github: url: 'https://www.graphiti.dev' - #url: 'http://localhost:4000' +# url: 'http://localhost:4000' defaults: - scope: path: "assets/img" diff --git a/guides/concepts/resources.md b/guides/concepts/resources.md index 338db82..a5e1bb9 100644 --- a/guides/concepts/resources.md +++ b/guides/concepts/resources.md @@ -623,6 +623,16 @@ end If a filter is marked `single: true`, we'll avoid any array parsing and escape the value for you, filtering on the string as given. +By default a value that comes in as `null` is treated as a string `"null"`. +To coerce `null` to a Ruby `nil` mark the filter with `allow_nil: true`. +This can be changed for all attributes by setting `filters_accept_nil_by_default` + +{% highlight ruby %} +class PostResource < ApplicationResource + self.filters_accept_nil_by_default = true +end +{% endhighlight %} + {% include h.html tag="h4" text="3.6 Statistics" a="statistics" %} Statistics are useful and common. Consider a datagrid listing posts - we might want a "Total Posts" count displayed above the grid without firing an additional request. Notably, that statistic **should** take into account filtering, but **should not** take into account pagination.