Class: GraphQL::ExecutionError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- GraphQL::ExecutionError
- 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.
Direct Known Subclasses
AnalysisError, CoercionError, LoadApplicationObjectFailedError, Query::OperationNameMissingError, Query::VariableValidationError, Schema::Timeout::TimeoutError, Schema::Validator::ValidationFailedError
Instance Attribute Summary collapse
-
#extensions ⇒ Hash
under the
extensionskey. -
#options ⇒ Hash
deprecated
Deprecated.
Use
extensionsinstead ofoptions. The GraphQL spec -
#path ⇒ String
response which corresponds to this error.
Instance Method Summary collapse
- #finalize_graphql_result(query, result_data, key) ⇒ Object
-
#initialize(message, ast_node: nil, ast_nodes: nil, options: nil, extensions: nil) ⇒ ExecutionError
constructor
A new instance of ExecutionError.
-
#to_h ⇒ Hash
An entry for the response's "errors" key.
Constructor Details
#initialize(message, ast_node: nil, ast_nodes: nil, options: nil, extensions: nil) ⇒ ExecutionError
Returns a new instance of ExecutionError.
21 22 23 24 25 26 |
# File 'lib/graphql/execution_error.rb', line 21 def initialize(, ast_node: nil, ast_nodes: nil, options: nil, extensions: nil) @ast_nodes = ast_nodes || [ast_node] @options = @extensions = extensions super() end |
Instance Attribute Details
#extensions ⇒ Hash
under the extensions key.
19 20 21 |
# File 'lib/graphql/execution_error.rb', line 19 def extensions @extensions end |
#options ⇒ Hash
Use extensions instead of options. The GraphQL spec
recommends that any custom entries in an error be under the
extensions key.
15 16 17 |
# File 'lib/graphql/execution_error.rb', line 15 def @options end |
#path ⇒ String
response which corresponds to this error.
9 10 11 |
# File 'lib/graphql/execution_error.rb', line 9 def path @path end |
Instance Method Details
#finalize_graphql_result(query, result_data, key) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/graphql/execution_error.rb', line 28 def finalize_graphql_result(query, result_data, key) if ast_node.is_a?(GraphQL::Language::Nodes::Directive) # This is for backwards compatibility ... what does the spec say? result_data.delete(key) else result_data[key] = nil end end |
#to_h ⇒ Hash
Returns An entry for the response's "errors" key.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/graphql/execution_error.rb', line 38 def to_h hash = { "message" => , } if ast_node hash["locations"] = @ast_nodes.map { |a| { "line" => a.line, "column" => a.col } } end if path hash["path"] = path end if hash.merge!() end if extensions hash["extensions"] = extensions.each_with_object({}) { |(key, value), ext| ext[key.to_s] = value } end hash end |