# loader.rb
def scoped(policy_scope = nil)
@policy_scope = policy_scope
self
end
def preload_association(records)
ActiveRecord::Associations::Preloader.new.preload(records, @association.name, @policy_scope)
end
# user_type.rb
def items
policy_scope = ItemPolicy::Scope.new(context[:current_user], Item).resolve
Association::Loader.for(object.class, :items).scoped(policy_scope).load(object)
end
Last active
June 9, 2022 14:57
-
-
Save masarakki/b55b9c3ac5c745683a77422bc02008e7 to your computer and use it in GitHub Desktop.
graphql-ruby with pundit policy_scope
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment