Class: GraphQL::Execution::Errors
- Inherits:
-
Object
- Object
- GraphQL::Execution::Errors
- Defined in:
- lib/graphql/execution/errors.rb
Overview
A plugin that wraps query execution with error handling. Supports class-based schemas and the new Interpreter runtime only.
Defined Under Namespace
Classes: NullErrorHandler
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(schema) ⇒ Errors
constructor
A new instance of Errors.
-
#with_error_handling(ctx) ⇒ Object
Call the given block with the schema’s configured error handlers.
Constructor Details
#initialize(schema) ⇒ Errors
Returns a new instance of Errors.
28 29 30 |
# File 'lib/graphql/execution/errors.rb', line 28 def initialize(schema) @schema = schema end |
Class Method Details
.use(schema) ⇒ Object
[View source]
20 21 22 23 24 25 26 |
# File 'lib/graphql/execution/errors.rb', line 20 def self.use(schema) if schema.plugins.any? { |(plugin, kwargs)| plugin == self } definition_line = caller(2, 1).first GraphQL::Deprecation.warn("GraphQL::Execution::Errors is now installed by default, remove `use GraphQL::Execution::Errors` from #{definition_line}") end schema.error_handler = self.new(schema) end |
Instance Method Details
#with_error_handling(ctx) ⇒ Object
Call the given block with the schema’s configured error handlers.
If the block returns a lazy value, it’s not wrapped with error handling. That area will have to be wrapped itself.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/graphql/execution/errors.rb', line 44 def with_error_handling(ctx) yield rescue StandardError => err rescues = ctx.schema.rescues _err_class, handler = rescues.find { |err_class, handler| err.is_a?(err_class) } if handler runtime_info = ctx.namespace(:interpreter) || {} obj = runtime_info[:current_object] args = runtime_info[:current_arguments] field = runtime_info[:current_field] if obj.is_a?(GraphQL::Schema::Object) obj = obj.object end handler.call(err, obj, args, ctx, field) else raise err end end |