File: unauthorized_field_error.rb

package info (click to toggle)
ruby-graphql 2.2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,584 kB
  • sloc: ruby: 67,505; ansic: 1,753; yacc: 831; javascript: 331; makefile: 6
file content (23 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true
module GraphQL
  class UnauthorizedFieldError < GraphQL::UnauthorizedError
    # @return [Field] the field that failed the authorization check
    attr_accessor :field

    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
  end
end