Exception: GraphQL::InvalidNullError

Inherits:
RuntimeError 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_or_nodes, is_from_array: false, path: nil) ⇒ InvalidNullError

Returns a new instance of InvalidNullError.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/graphql/invalid_null_error.rb', line 24

def initialize(parent_type, field, ast_node_or_nodes, is_from_array: false, path: nil)
  @parent_type = parent_type
  @field = field
  @ast_nodes = Array(ast_node_or_nodes)
  @is_from_array = is_from_array
  @path = path
  # 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.



42
43
44
# File 'lib/graphql/invalid_null_error.rb', line 42

def parent_class
  @parent_class
end

Instance Attribute Details

#ast_nodesObject (readonly)

Returns the value of attribute ast_nodes.



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

def ast_nodes
  @ast_nodes
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



20
21
22
# File 'lib/graphql/invalid_null_error.rb', line 20

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

#pathObject

Returns the value of attribute path.



22
23
24
# File 'lib/graphql/invalid_null_error.rb', line 22

def path
  @path
end

Class Method Details

.inspectObject



50
51
52
53
54
55
56
# File 'lib/graphql/invalid_null_error.rb', line 50

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



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

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

Instance Method Details

#ast_nodeGraphQL::Language::Nodes::Field

Returns the field where the error occurred.

Returns:



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

def ast_node
  @ast_nodes.first
end