Sha256: 937f70f2c7bee520016df3c550d6bef8452dceebeaa8b6c21ef945cacd246d3e

Contents?: true

Size: 1.07 KB

Versions: 44

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true
module GraphQL
  # When an `authorized?` hook returns false, this error is used to communicate the failure.
  # It's passed to {Schema.unauthorized_object}.
  #
  # Alternatively, custom code in `authorized?` may raise this error. It will be routed the same way.
  class UnauthorizedError < GraphQL::Error
    # @return [Object] the application object that failed the authorization check
    attr_reader :object

    # @return [Class] the GraphQL object type whose `.authorized?` method was called (and returned false)
    attr_reader :type

    # @return [GraphQL::Query::Context] the context for the current query
    attr_reader :context

    def initialize(message = nil, object: nil, type: nil, context: nil)
      if message.nil? && object.nil? && type.nil?
        raise ArgumentError, "#{self.class.name} requires either a message or keywords"
      end

      @object = object
      @type = type
      @context = context
      message ||= "An instance of #{object.class} failed #{type.name}'s authorization check"
      super(message)
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
graphql-1.11.5 lib/graphql/unauthorized_error.rb
graphql-1.11.4 lib/graphql/unauthorized_error.rb
graphql-1.11.3 lib/graphql/unauthorized_error.rb
graphql-1.11.2 lib/graphql/unauthorized_error.rb
graphql-1.10.14 lib/graphql/unauthorized_error.rb
graphql-1.11.1 lib/graphql/unauthorized_error.rb
graphql-1.10.13 lib/graphql/unauthorized_error.rb
graphql-1.11.0 lib/graphql/unauthorized_error.rb
graphql-1.10.12 lib/graphql/unauthorized_error.rb
graphql-1.9.21 lib/graphql/unauthorized_error.rb
graphql-1.10.11 lib/graphql/unauthorized_error.rb
graphql-1.9.20 lib/graphql/unauthorized_error.rb
graphql-1.10.10 lib/graphql/unauthorized_error.rb
graphql-1.10.9 lib/graphql/unauthorized_error.rb
graphql-1.10.8 lib/graphql/unauthorized_error.rb
graphql-1.10.7 lib/graphql/unauthorized_error.rb
graphql-1.10.6 lib/graphql/unauthorized_error.rb
graphql-1.10.5 lib/graphql/unauthorized_error.rb
graphql-1.10.4 lib/graphql/unauthorized_error.rb
graphql-1.10.3 lib/graphql/unauthorized_error.rb