Class: GraphQL::Pundit::Instrumenters::Authorization::AuthorizationResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql-pundit/instrumenters/authorization.rb

Overview

This does the actual Pundit authorization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, old_resolver, options) ⇒ AuthorizationResolver

Returns a new instance of AuthorizationResolver.



13
14
15
16
17
# File 'lib/graphql-pundit/instrumenters/authorization.rb', line 13

def initialize(current_user, old_resolver, options)
  @current_user = current_user
  @old_resolver = old_resolver
  @options = options
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



12
13
14
# File 'lib/graphql-pundit/instrumenters/authorization.rb', line 12

def current_user
  @current_user
end

#old_resolverObject (readonly)

Returns the value of attribute old_resolver.



12
13
14
# File 'lib/graphql-pundit/instrumenters/authorization.rb', line 12

def old_resolver
  @old_resolver
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/graphql-pundit/instrumenters/authorization.rb', line 12

def options
  @options
end

Instance Method Details

#call(root, arguments, context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/graphql-pundit/instrumenters/authorization.rb', line 19

def call(root, arguments, context)
  unless authorize(root, arguments, context)
    raise ::Pundit::NotAuthorizedError
  end
  old_resolver.call(root, arguments, context)
rescue ::Pundit::NotAuthorizedError
  if options[:raise]
    raise GraphQL::ExecutionError, "You're not authorized to do this"
  end
end