Class: GraphQL::UnauthorizedFieldError

Inherits:
UnauthorizedError
  • Object
show all
Defined in:
lib/graphql/unauthorized_field_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of UnauthorizedFieldError.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphql/unauthorized_field_error.rb', line 11

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

  @field = field
  message ||= begin
    if object
      "An instance of #{object.class} failed #{type.name}'s authorization check on field #{field.name}"
    else
      "Failed #{type.name}'s authorization check on field #{field.name}"
    end
  end
  super(message, object: object, type: type, context: context)
end

Instance Attribute Details

#field ⇒ Object

Returns

  • Field — the field that failed the authorization check


9
10
11
# File 'lib/graphql/unauthorized_field_error.rb', line 9

def field
  @field
end