Sha256: 59684936f1b48df1b6de58df0d301c443695fd27616cebaff80ff203778aa074

Contents?: true

Size: 1.33 KB

Versions: 76

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true
require "graphql/backtrace/inspect_result"
require "graphql/backtrace/table"
require "graphql/backtrace/traced_error"
require "graphql/backtrace/tracer"
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}.
  #
  # WARNING: {.enable} is not threadsafe because {GraphQL::Tracing.install} is not threadsafe.
  #
  # @example toggling backtrace annotation
  #   # to enable:
  #   GraphQL::Backtrace.enable
  #   # later, to disable:
  #   GraphQL::Backtrace.disable
  #
  class Backtrace
    include Enumerable
    extend Forwardable

    def_delegators :to_a, :each, :[]

    def self.enable
      warn("GraphQL::Backtrace.enable is deprecated, add `use GraphQL::Backtrace` to your schema definition instead.")
      GraphQL::Tracing.install(Backtrace::Tracer)
      nil
    end

    def self.disable
      GraphQL::Tracing.uninstall(Backtrace::Tracer)
      nil
    end

    def self.use(schema_defn)
      schema_defn.tracer(self::Tracer)
    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

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
graphql-1.11.10 lib/graphql/backtrace.rb
graphql-1.11.9 lib/graphql/backtrace.rb
graphql-1.11.8 lib/graphql/backtrace.rb
graphql-1.11.7 lib/graphql/backtrace.rb
graphql-1.11.6 lib/graphql/backtrace.rb
graphql-1.8.18 lib/graphql/backtrace.rb
graphql-1.11.5 lib/graphql/backtrace.rb
graphql-1.11.4 lib/graphql/backtrace.rb
graphql-1.11.3 lib/graphql/backtrace.rb
graphql-1.11.2 lib/graphql/backtrace.rb
graphql-1.10.14 lib/graphql/backtrace.rb
graphql-1.11.1 lib/graphql/backtrace.rb
graphql-1.10.13 lib/graphql/backtrace.rb
graphql-1.11.0 lib/graphql/backtrace.rb
graphql-1.10.12 lib/graphql/backtrace.rb
graphql-1.9.21 lib/graphql/backtrace.rb
graphql-1.10.11 lib/graphql/backtrace.rb
graphql-1.9.20 lib/graphql/backtrace.rb
graphql-1.10.10 lib/graphql/backtrace.rb
graphql-1.10.9 lib/graphql/backtrace.rb