Class: GraphQL::UnauthorizedError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/graphql/unauthorized_error.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, object: nil, type: nil, context: nil) ⇒ UnauthorizedError

Returns a new instance of UnauthorizedError.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/graphql/unauthorized_error.rb', line 25

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

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

Instance Attribute Details

#ast_nodes ⇒ Object

Returns the value of attribute ast_nodes.



39
40
41
# File 'lib/graphql/unauthorized_error.rb', line 39

def ast_nodes
  @ast_nodes
end

#context ⇒ Object

Returns

  • GraphQL::Query::Context — the context for the current query


23
24
25
# File 'lib/graphql/unauthorized_error.rb', line 23

def context
  @context
end

#object ⇒ Object (readonly)

Returns

  • Object — the application object that failed the authorization check


13
14
15
# File 'lib/graphql/unauthorized_error.rb', line 13

def object
  @object
end

#path ⇒ Object

Returns the value of attribute path.



39
40
41
# File 'lib/graphql/unauthorized_error.rb', line 39

def path
  @path
end

#type ⇒ Object (readonly)

Returns

  • Class — the GraphQL object type whose .authorized? method was called (and returned false)


18
19
20
# File 'lib/graphql/unauthorized_error.rb', line 18

def type
  @type
end

Instance Method Details

#finalize_graphql_result(query, result_data, key) ⇒ Object



41
42
43
# File 'lib/graphql/unauthorized_error.rb', line 41

def finalize_graphql_result(query, result_data, key)
  result_data[key] = nil
end