Module: GraphQR::Base
- Includes:
- ApplyScopes
- Defined in:
- lib/graphqr/base.rb
Overview
The Base module defines some helper methods that can be used once it is included it also includes the basic ApplyScopes library
Constant Summary collapse
- DEFAULT_AUTHORIZATION_ERROR =
'You are not authorized to perform this action'
Instance Method Summary collapse
-
#authorize_graphql(record, action, policy_class: nil) ⇒ Object
This method is a wrapper around the Pundit authorize, receiving the same arguments.
-
#policy_provider ⇒ Object
This is a helper method to get the policy provider from the context.
Methods included from ApplyScopes
Instance Method Details
#authorize_graphql(record, action, policy_class: nil) ⇒ Object
This method is a wrapper around the Pundit authorize, receiving the same arguments. The only difference is that it turns the Pundit::NotAuthorizedError into a GraphQL::ExecutionError
### Example:
“‘ authorize_graphql User, :index? “`
21 22 23 24 |
# File 'lib/graphqr/base.rb', line 21 def (record, action, policy_class: nil) args = { record: record, action: action, policy_class: policy_class } raise GraphQL::ExecutionError, DEFAULT_AUTHORIZATION_ERROR unless policy_provider.allowed?(args) end |
#policy_provider ⇒ Object
This is a helper method to get the policy provider from the context
28 29 30 |
# File 'lib/graphqr/base.rb', line 28 def policy_provider context[:policy_provider] end |