Sha256: 28e084d4715409eb7ed84d5fb46f1a1671760c33b3a1a3a039e9a38908bd78dc

Contents?: true

Size: 1.37 KB

Versions: 17

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true
module GraphQL
  # Raised automatically when a field's resolve function returns `nil`
  # for a non-null field.
  class InvalidNullError < GraphQL::RuntimeTypeError
    # @return [GraphQL::BaseType] The owner of {#field}
    attr_reader :parent_type

    # @return [GraphQL::Field] The field which failed to return a value
    attr_reader :field

    # @return [nil, GraphQL::ExecutionError] The invalid value for this field
    attr_reader :value

    def initialize(parent_type, field, value)
      @parent_type = parent_type
      @field = field
      @value = value
      super("Cannot return null for non-nullable field #{@parent_type.graphql_name}.#{@field.graphql_name}")
    end

    # @return [Hash] An entry for the response's "errors" key
    def to_h
      { "message" => message }
    end

    # @deprecated always false
    def parent_error?
      false
    end

    class << self
      attr_accessor :parent_class

      def subclass_for(parent_class)
        subclass = Class.new(self)
        subclass.parent_class = parent_class
        subclass
      end

      def inspect
        if (name.nil? || parent_class&.name.nil?) && parent_class.respond_to?(:mutation) && (mutation = parent_class.mutation)
          "#{mutation.inspect}::#{parent_class.graphql_name}::InvalidNullError"
        else
          super
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
graphql-2.3.22 lib/graphql/invalid_null_error.rb
graphql-2.3.21 lib/graphql/invalid_null_error.rb
graphql-2.4.10 lib/graphql/invalid_null_error.rb
graphql-2.4.9 lib/graphql/invalid_null_error.rb
graphql-2.4.8 lib/graphql/invalid_null_error.rb
graphql-2.4.7 lib/graphql/invalid_null_error.rb
graphql-2.4.6 lib/graphql/invalid_null_error.rb
graphql-2.4.5 lib/graphql/invalid_null_error.rb
graphql-2.4.4 lib/graphql/invalid_null_error.rb
graphql-2.4.3 lib/graphql/invalid_null_error.rb
graphql-2.4.2 lib/graphql/invalid_null_error.rb
graphql-2.4.1 lib/graphql/invalid_null_error.rb
graphql-2.4.0 lib/graphql/invalid_null_error.rb
graphql-2.3.20 lib/graphql/invalid_null_error.rb
graphql-2.3.19 lib/graphql/invalid_null_error.rb
graphql-2.3.18 lib/graphql/invalid_null_error.rb
graphql-2.3.17 lib/graphql/invalid_null_error.rb