Exception: GraphQL::ExecutionError

Inherits:
RuntimeError 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, ast_nodes: nil, options: nil, extensions: nil) ⇒ ExecutionError

Returns a new instance of ExecutionError.



32
33
34
35
36
37
# File 'lib/graphql/execution_error.rb', line 32

def initialize(message, ast_node: nil, ast_nodes: nil, options: nil, extensions: nil)
  @ast_nodes = ast_nodes || [ast_node]
  @options = options
  @extensions = extensions
  super(message)
end

Instance Attribute Details

#ast_nodesObject

Returns the value of attribute ast_nodes.



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

def ast_nodes
  @ast_nodes
end

#extensionsHash

under the extensions key.

Returns:

  • (Hash)

    Optional custom data for error objects which will be added



30
31
32
# File 'lib/graphql/execution_error.rb', line 30

def extensions
  @extensions
end

#optionsHash

Deprecated.

Use extensions instead of options. The GraphQL spec

recommends that any custom entries in an error be under the extensions key.

Returns:

  • (Hash)

    Optional data for error objects



26
27
28
# File 'lib/graphql/execution_error.rb', line 26

def options
  @options
end

#pathString

response which corresponds to this error.

Returns:

  • (String)

    an array describing the JSON-path into the execution



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

def path
  @path
end

Instance Method Details

#ast_nodeGraphQL::Language::Nodes::Field

Returns the field where the error occurred.

Returns:



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

def ast_node
  ast_nodes.first
end

#ast_node=(new_node) ⇒ Object



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

def ast_node=(new_node)
  @ast_nodes = [new_node]
end

#to_hHash

Returns An entry for the response’s “errors” key.

Returns:

  • (Hash)

    An entry for the response’s “errors” key



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/graphql/execution_error.rb', line 40

def to_h
  hash = {
    "message" => message,
  }
  if ast_node
    hash["locations"] = @ast_nodes.map { |a| { "line" => a.line, "column" => a.col } }
  end
  if path
    hash["path"] = path
  end
  if options
    hash.merge!(options)
  end
  if extensions
    hash["extensions"] = extensions.each_with_object({}) { |(key, value), ext|
      ext[key.to_s] = value
    }
  end
  hash
end