Exception: GraphQL::ExecutionError

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

Overview

If a field's resolve function returns a ExecutionError, the error will be inserted into the response's "errors" key and the field will resolve to nil.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, ast_node: nil) ⇒ ExecutionError

Returns a new instance of ExecutionError


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

def initialize(message, ast_node: nil)
  @ast_node = ast_node
  super(message)
end

Instance Attribute Details

#ast_nodeGraphQL::Language::Nodes::Field

Returns the field where the error occured

Returns:


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

def ast_node
  @ast_node
end

#pathString

response which corresponds to this error.

Returns:

  • (String)

    an array describing the JSON-path into the execution


11
12
13
# File 'lib/graphql/execution_error.rb', line 11

def path
  @path
end

Instance Method Details

#to_hHash

Returns An entry for the response's "errors" key

Returns:

  • (Hash)

    An entry for the response's "errors" key


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

def to_h
  hash = {
    "message" => message,
  }
  if ast_node
    hash["locations"] = [
      {
        "line" => ast_node.line,
        "column" => ast_node.col,
      }
    ]
  end
  if path
    hash["path"] = path
  end
  hash
end