Exception: 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, InvalidNameError, LoadApplicationObjectFailedError, Query::OperationNameMissingError, Query::VariableValidationError, Schema::Timeout::TimeoutError, Schema::Validator::ValidationFailedError
Instance Attribute Summary collapse
-
#ast_node ⇒ GraphQL::Language::Nodes::Field
The field where the error occurred.
-
#extensions ⇒ Hash
under the
extensions
key. -
#options ⇒ Hash
deprecated
Deprecated.
Use
extensions
instead ofoptions
. The GraphQL spec -
#path ⇒ String
response which corresponds to this error.
Instance Method Summary collapse
-
#initialize(message, ast_node: 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, options: nil, extensions: nil) ⇒ ExecutionError
Returns a new instance of ExecutionError.
24 25 26 27 28 29 |
# File 'lib/graphql/execution_error.rb', line 24 def initialize(, ast_node: nil, options: nil, extensions: nil) @ast_node = ast_node @options = @extensions = extensions super() end |
Instance Attribute Details
#ast_node ⇒ GraphQL::Language::Nodes::Field
Returns the field where the error occurred.
8 9 10 |
# File 'lib/graphql/execution_error.rb', line 8 def ast_node @ast_node end |
#extensions ⇒ Hash
under the extensions
key.
22 23 24 |
# File 'lib/graphql/execution_error.rb', line 22 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.
18 19 20 |
# File 'lib/graphql/execution_error.rb', line 18 def @options end |
#path ⇒ String
response which corresponds to this error.
12 13 14 |
# File 'lib/graphql/execution_error.rb', line 12 def path @path end |
Instance Method Details
#to_h ⇒ Hash
Returns An entry for the response's "errors" key.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/graphql/execution_error.rb', line 32 def to_h hash = { "message" => , } if ast_node hash["locations"] = [ { "line" => ast_node.line, "column" => ast_node.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 |