Class: GraphQL::UnauthorizedError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- GraphQL::UnauthorizedError
- 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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ast_nodes ⇒ Object
Returns the value of attribute ast_nodes.
-
#context ⇒ Object
Returns.
-
#object ⇒ Object
readonly
Returns.
-
#path ⇒ Object
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns.
Instance Method Summary collapse
- #finalize_graphql_result(query, result_data, key) ⇒ Object
-
#initialize(message = nil, object: nil, type: nil, context: nil) ⇒ UnauthorizedError
constructor
A new instance of UnauthorizedError.
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( = nil, object: nil, type: nil, context: nil) if .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 ||= "An instance of #{object.class} failed #{type.graphql_name}'s authorization check" super() 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 |