Class: GraphQL::Execution::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/execution/errors.rb

Overview

A tracer that wraps query execution with error handling. Supports class-based schemas and the new Interpreter runtime only.

Examples:

Handling ActiveRecord::NotFound


class MySchema < GraphQL::Schema
  use GraphQL::Execution::Errors

  rescue_from(ActiveRecord::NotFound) do |err, obj, args, ctx, field|
    ErrorTracker.log("Not Found: #{err.message}")
    nil
  end
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Errors

Returns a new instance of Errors



25
26
27
# File 'lib/graphql/execution/errors.rb', line 25

def initialize(schema)
  @schema = schema
end

Class Method Details

.use(schema) ⇒ Object



20
21
22
23
# File 'lib/graphql/execution/errors.rb', line 20

def self.use(schema)
  schema_class = schema.is_a?(Class) ? schema : schema.target.class
  schema.tracer(self.new(schema_class))
end

Instance Method Details

#trace(event, data) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/graphql/execution/errors.rb', line 29

def trace(event, data)
  case event
  when "execute_field", "execute_field_lazy"
    with_error_handling(data) { yield }
  else
    yield
  end
end