-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathbacktrace.rb
41 lines (35 loc) · 921 Bytes
/
backtrace.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true
require "graphql/backtrace/table"
require "graphql/backtrace/traced_error"
module GraphQL
# Wrap unhandled errors with {TracedError}.
#
# {TracedError} provides a GraphQL backtrace with arguments and return values.
# The underlying error is available as {TracedError#cause}.
#
# @example toggling backtrace annotation
# class MySchema < GraphQL::Schema
# if Rails.env.development? || Rails.env.test?
# use GraphQL::Backtrace
# end
# end
#
class Backtrace
include Enumerable
extend Forwardable
def_delegators :to_a, :each, :[]
def self.use(schema_defn)
schema_defn.using_backtrace = true
end
def initialize(context, value: nil)
@table = Table.new(context, value: value)
end
def inspect
@table.to_table
end
alias :to_s :inspect
def to_a
@table.to_backtrace
end
end
end