Module: GraphQR::ScopeItems

Defined in:
lib/graphqr/scope_items.rb

Overview

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`

Instance Method Summary collapse

Instance Method Details

#scope_items(items, context) ⇒ Object

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



14
15
16
17
18
19
20
# 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