class ActionPolicy::GraphQL::AuthorizedField::AuthorizeExtension

Constants

DEPRECATION_MESSAGE

Public Class Methods

show_authorize_mutation_deprecation() click to toggle source
# File lib/action_policy/graphql/authorized_field.rb, line 28
def show_authorize_mutation_deprecation
  return if defined?(@authorize_mutation_deprecation_shown)

  if defined?(ActiveSupport::Deprecation)
    ActiveSupport::Deprecation.warn(DEPRECATION_MESSAGE)
  else
    warn(DEPRECATION_MESSAGE)
  end

  @authorize_mutation_deprecation_shown = true
end

Public Instance Methods

after_resolve(value:, context:, object:, **_rest) click to toggle source
# File lib/action_policy/graphql/authorized_field.rb, line 48
def after_resolve(value:, context:, object:, **_rest)
  return value if value.nil?

  if @raise
    object.authorize! value, to: @to, **options
    value
  else
    object.allowed_to?(@to, value, **options) ? value : nil
  end
end
apply() click to toggle source
# File lib/action_policy/graphql/authorized_field.rb, line 41
def apply
  self.class.show_authorize_mutation_deprecation if field.mutation && field.mutation < ::GraphQL::Schema::Mutation

  @to = extract_option(:to) { ::ActionPolicy::GraphQL.default_authorize_rule }
  @raise = extract_option(:raise) { ::ActionPolicy::GraphQL.authorize_raise_exception }
end