stackshareio/graphql-cache

"cache if" feature

jeromedalbert opened this issue · 1 comments

Similar to Rails views:

- cache_if (current_user.nil?) do

And actionpack-action_caching:

caches_action :show, if: -> { current_user.nil? }

It would be nice to be able to do something like this in graphql-cache:

field :calculated_field, Int, cache: { if: -> { current_user.nil? } }

Although the double-brackets might feel awkward, so it might look cleaner to do

field :calculated_field, Int do
  cache if: -> { current_user.nil? }
end

(which is related to my second bullet point on #52 referring to the ability to have cache on its own line)

I agree this would be nice. On our site we'd like to disable the cache for logged in users.