Sha256: d9ba5daa8e1bf86f14ac8c91a80d0fefc14bf96038ae975ed678d11edb753454

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 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 GraphQL::Delegate

    def_delegators :to_a, :each, :[]

    def self.enable
      GraphQL::Tracing.install(Backtrace::Tracer)
      nil
    end

    def self.disable
      GraphQL::Tracing.uninstall(Backtrace::Tracer)
      nil
    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

4 entries across 4 versions & 1 rubygems

Version Path
graphql-1.7.3 lib/graphql/backtrace.rb
graphql-1.7.2 lib/graphql/backtrace.rb
graphql-1.7.1 lib/graphql/backtrace.rb
graphql-1.7.0 lib/graphql/backtrace.rb