Sha256: 67dcd3290df67f0e977c28ed43e9c8e89e76640cdcc5455c5b5b73215a7b7e00

Contents?: true

Size: 1.08 KB

Versions: 117

Compression:

Stored size: 1.08 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_accessor :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.graphql_name}'s authorization check"
      super(message)
    end
  end
end

Version data entries

117 entries across 117 versions & 2 rubygems

Version Path
graphql-2.4.4 lib/graphql/unauthorized_error.rb
graphql-2.4.3 lib/graphql/unauthorized_error.rb
graphql-2.4.2 lib/graphql/unauthorized_error.rb
graphql-2.4.1 lib/graphql/unauthorized_error.rb
graphql-2.4.0 lib/graphql/unauthorized_error.rb
graphql-2.3.20 lib/graphql/unauthorized_error.rb
graphql-2.3.19 lib/graphql/unauthorized_error.rb
graphql-2.3.18 lib/graphql/unauthorized_error.rb
graphql-2.3.17 lib/graphql/unauthorized_error.rb
graphql-2.3.16 lib/graphql/unauthorized_error.rb
graphql-2.3.15 lib/graphql/unauthorized_error.rb
graphql-2.3.14 lib/graphql/unauthorized_error.rb
graphql-2.3.13 lib/graphql/unauthorized_error.rb
graphql-2.3.12 lib/graphql/unauthorized_error.rb
graphql-2.3.11 lib/graphql/unauthorized_error.rb
graphql-2.3.10 lib/graphql/unauthorized_error.rb
graphql-2.2.16 lib/graphql/unauthorized_error.rb
graphql-2.1.13 lib/graphql/unauthorized_error.rb
graphql-2.3.9 lib/graphql/unauthorized_error.rb
graphql-2.3.8 lib/graphql/unauthorized_error.rb