Exception: GraphQL::InvalidNullError

Inherits:
Error
  • Object
show all
Defined in:
lib/graphql/invalid_null_error.rb

Overview

Raised automatically when a field’s resolve function returns nil for a non-null field.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_type, field, ast_node, is_from_array: false) ⇒ InvalidNullError

Returns a new instance of InvalidNullError.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/graphql/invalid_null_error.rb', line 18

def initialize(parent_type, field, ast_node, is_from_array: false)
  @parent_type = parent_type
  @field = field
  @ast_node = ast_node
  @is_from_array = is_from_array

  # For List elements, identify the non-null error is for an
  # element and the required element type so it's not ambiguous
  # whether it was caused by a null instead of the list or a
  # null element.
  if @is_from_array
    super("Cannot return null for non-nullable element of type '#{@field.type.of_type.of_type.to_type_signature}' for #{@parent_type.graphql_name}.#{@field.graphql_name}")
  else
    super("Cannot return null for non-nullable field #{@parent_type.graphql_name}.#{@field.graphql_name}")
  end
end

Class Attribute Details

.parent_classObject

Returns the value of attribute parent_class.



36
37
38
# File 'lib/graphql/invalid_null_error.rb', line 36

def parent_class
  @parent_class
end

Instance Attribute Details

#ast_nodeGraphQL::Language::Nodes::Field (readonly)

Returns the field where the error occurred.

Returns:



13
14
15
# File 'lib/graphql/invalid_null_error.rb', line 13

def ast_node
  @ast_node
end

#fieldGraphQL::Field (readonly)

Returns The field which failed to return a value.

Returns:

  • (GraphQL::Field)

    The field which failed to return a value



10
11
12
# File 'lib/graphql/invalid_null_error.rb', line 10

def field
  @field
end

#is_from_arrayBoolean (readonly)

Returns indicates an array result caused the error.

Returns:

  • (Boolean)

    indicates an array result caused the error



16
17
18
# File 'lib/graphql/invalid_null_error.rb', line 16

def is_from_array
  @is_from_array
end

#parent_typeGraphQL::BaseType (readonly)

Returns The owner of #field.

Returns:

  • (GraphQL::BaseType)

    The owner of #field



7
8
9
# File 'lib/graphql/invalid_null_error.rb', line 7

def parent_type
  @parent_type
end

Class Method Details

.inspectObject



44
45
46
47
48
49
50
# File 'lib/graphql/invalid_null_error.rb', line 44

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

.subclass_for(parent_class) ⇒ Object



38
39
40
41
42
# File 'lib/graphql/invalid_null_error.rb', line 38

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