Sha256: 065669be760766e2ac6fefe3e1bbd37145a0c7e7186431c35ca3573f72edaeb7

Contents?: true

Size: 1.37 KB

Versions: 131

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

131 entries across 131 versions & 2 rubygems

Version Path
graphql-2.3.16 lib/graphql/invalid_null_error.rb
graphql-2.3.15 lib/graphql/invalid_null_error.rb
graphql-2.3.14 lib/graphql/invalid_null_error.rb
graphql-2.3.13 lib/graphql/invalid_null_error.rb
graphql-2.3.12 lib/graphql/invalid_null_error.rb
graphql-2.3.11 lib/graphql/invalid_null_error.rb
graphql-2.3.10 lib/graphql/invalid_null_error.rb
graphql-2.2.16 lib/graphql/invalid_null_error.rb
graphql-2.1.13 lib/graphql/invalid_null_error.rb
graphql-2.3.9 lib/graphql/invalid_null_error.rb
graphql-2.3.8 lib/graphql/invalid_null_error.rb
graphql-2.3.7 lib/graphql/invalid_null_error.rb
graphql-2.3.6 lib/graphql/invalid_null_error.rb
graphql-2.3.5 lib/graphql/invalid_null_error.rb
graphql-2.0.31 lib/graphql/invalid_null_error.rb
graphql-2.3.2 lib/graphql/invalid_null_error.rb
graphql-2.3.1 lib/graphql/invalid_null_error.rb
graphql-1.13.23 lib/graphql/invalid_null_error.rb
graphql-2.3.0 lib/graphql/invalid_null_error.rb
graphql-2.2.14 lib/graphql/invalid_null_error.rb