Class: GraphQL::InvalidNullError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- GraphQL::InvalidNullError
- 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
-
.parent_class ⇒ Object
Returns the value of attribute parent_class.
Instance Attribute Summary collapse
-
#ast_nodes ⇒ Object
readonly
Returns the value of attribute ast_nodes.
-
#field ⇒ Object
readonly
Returns.
-
#is_from_array ⇒ Object
readonly
Returns.
-
#parent_type ⇒ Object
readonly
Returns.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#ast_node ⇒ Object
Returns.
-
#initialize(parent_type, field, ast_node_or_nodes, is_from_array: false, path: nil, element_type: nil) ⇒ InvalidNullError
constructor
A new instance of InvalidNullError.
Constructor Details
#initialize(parent_type, field, ast_node_or_nodes, is_from_array: false, path: nil, element_type: nil) ⇒ InvalidNullError
Returns a new instance of InvalidNullError.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/graphql/invalid_null_error.rb', line 37 def initialize(parent_type, field, ast_node_or_nodes, is_from_array: false, path: nil, element_type: 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 element_type ||= @field.type.of_type.of_type super("Cannot return null for non-nullable element of type '#{element_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_class ⇒ Object
Returns the value of attribute parent_class.
56 57 58 |
# File 'lib/graphql/invalid_null_error.rb', line 56 def parent_class @parent_class end |
Instance Attribute Details
#ast_nodes ⇒ Object (readonly)
Returns the value of attribute ast_nodes.
28 29 30 |
# File 'lib/graphql/invalid_null_error.rb', line 28 def ast_nodes @ast_nodes end |
#field ⇒ Object (readonly)
Returns
GraphQL::Field— The field which failed to return a value
16 17 18 |
# File 'lib/graphql/invalid_null_error.rb', line 16 def field @field end |
#is_from_array ⇒ Object (readonly)
Returns
Boolean— indicates an array result caused the error
33 34 35 |
# File 'lib/graphql/invalid_null_error.rb', line 33 def is_from_array @is_from_array end |
#parent_type ⇒ Object (readonly)
Returns
GraphQL::BaseType— The owner of field
11 12 13 |
# File 'lib/graphql/invalid_null_error.rb', line 11 def parent_type @parent_type end |
#path ⇒ Object
Returns the value of attribute path.
35 36 37 |
# File 'lib/graphql/invalid_null_error.rb', line 35 def path @path end |
Class Method Details
.inspect ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/graphql/invalid_null_error.rb', line 64 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
58 59 60 61 62 |
# File 'lib/graphql/invalid_null_error.rb', line 58 def subclass_for(parent_class) subclass = Class.new(self) subclass.parent_class = parent_class subclass end |
Instance Method Details
#ast_node ⇒ Object
Returns
GraphQL::Language::Nodes::Field— the field where the error occurred
:call-seq:
ast_node() -> GraphQL::Language::Nodes::Field
24 25 26 |
# File 'lib/graphql/invalid_null_error.rb', line 24 def ast_node @ast_nodes.first end |