Class: Stardust::GraphQL::Extensions::Authorize

Inherits:
GraphQL::Schema::FieldExtension
  • Object
show all
Defined in:
lib/stardust/graphql/extensions/authorize.rb

Instance Method Summary collapse

Instance Method Details

#after_resolve(object:, arguments:, context:, value:, memo:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/stardust/graphql/extensions/authorize.rb', line 6

def after_resolve(object:, arguments:, context:, value:, memo:)
  klass = field.instance_variable_get(:@resolver_class)
  instance = klass.new(object: object, context: context)

  if instance.respond_to?(:authorized?)
    unless instance.authorized?(value: value, context: context, arguments: arguments)
      raise ::GraphQL::ExecutionError, "Not authorized to access"
    end
  end
  
  value
end