-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Unable to use] graphql-ruby-fragment_cache + action_policy-graphql #68
Comments
Hi @danielnc! When there is a cache hit, an instance of
I feel like the only way to make it work is to move scoping into the resolver method: field :collections, [CollectionType], null: false, cache_fragment: { context_key: :current_user }
def collections
authorized_scope(Collection, type: :relation)
end I feel like we could fix it by performing cache checks before policy ones (because we cache only scoped data, so it should be safe). @palkan do you think it's possible? |
That's interesting. So, fragment cache doesn't halt the field resolution, right? Maybe, a quick fix would be to add a passthrough policy for For example: class PassthroughPolicy < ApplicationPolicy
relation_scope(&:itself)
end
GraphQL::Execution::Interpreter::RawValue.define_singleton_method(:policy_class) { PassthroughPolicy } |
It halts the resolution of all nested fields and returns the value as-is. Looks like policy checks are run against the returned value after that. @danielnc could you please try the snipped above? I guess we could make it a part of the gem later |
@DmitryTsepelev / @palkan this code works for the first time when there is no cached value, for a second execution when there is a cached value, it's still throwing the same error: and just a FYI, doing is not the same as adding |
I landed on this issue with the same problem. I was able to get around this with action policy by combining a custom scope matcher and policy. Here's the gist of it: In an initializer:
graphql_fragment_cache_policy.rb:
It's worth noting that our cache keys are granular enough to account for our various user / permission contexts. |
I am trying to use both fragment caching + action policy and due to lack of documentation I am unable to make it work if I have a
authorized_scope: true
if my fieldif I have a field like this:
field :collections, [CollectionType], null: false, authorized_scope: true, cache_fragment: { context_key: :current_user } do
I get an error:
If I add a explicit policy:
I get a different error:
It works flawlessly for fields without authorization scope, so not sure what I need to add/change on my end or what is missing
The text was updated successfully, but these errors were encountered: