Skip to content

Commit 96aa637

Browse files
committed
Add documentation
1 parent 682cf37 commit 96aa637

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,34 @@ class QueryType < BaseObject
147147
end
148148
```
149149

150+
### Query arguments processing
151+
152+
You can influence the way that graphql arguments are include in the cache key.
153+
154+
A use case might be a `:renew_cache` parameter that can be used to force a cache rewrite,
155+
but should not be included with the cache key itself. Use `cache_key: { exclude_arguments: […]}`
156+
to specify a list of arguments to be excluded from the implicit cache key.
157+
158+
```ruby
159+
class QueryType < BaseObject
160+
field :post, PostType, null: true do
161+
argument :id, ID, required: true
162+
argument :renew_cache, Boolean, required: false
163+
end
164+
165+
def post(id:, renew_cache: false)
166+
if renew_cache
167+
context.scoped_set!(:renew_cache, true)
168+
end
169+
cache_fragment(cache_key: { exclude_arguments: [:renew_cache] }) { Post.find(id) }
170+
end
171+
end
172+
```
173+
174+
Likewise, you can use `cache_key: { include_arguments: […] }` to specify an allowlist of arguments
175+
to be included in the cache key. In this case all arguments for the cache key must be specified, including
176+
parent arguments of nested fields.
177+
150178
### User-provided cache key (custom key)
151179

152180
In most cases you want your cache key to depend on the resolved object (say, `ActiveRecord` model). You can do that by passing an argument to the `#cache_fragment` method in a similar way to Rails views [`#cache` method](https://guides.rubyonrails.org/caching_with_rails.html#fragment-caching):

0 commit comments

Comments
 (0)