module GraphQR::ScopeItems

This extension adds the PolicyProvider scope to the fields. When using the extension, ActiveRecord::Relation fields will be scoped.

To use this extension add extend GraphQR::ScopeItems on the GraphQL::Schema::Object you want, or in your BaseObject

Public Instance Methods

scope_items(items, context) click to toggle source

The method checks whether the items are a ActiveRecord::Relation or not. If they are, it runs the PolicyProvider authorized_records scope.

# File lib/graphqr/scope_items.rb, line 14
def scope_items(items, context)
  if scopable_items?(items)
    context[:policy_provider].authorized_records(records: items)
  else
    items
  end
end