Sha256: 05943f3a21c78340c7970e295e3a160997d8c8a00a99c29489e8c9323c906938

Contents?: true

Size: 1.56 KB

Versions: 50

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true
require "graphql/backtrace/inspect_result"
require "graphql/backtrace/legacy_tracer"
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}.
  #
  # @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, legacy: false)
      tracer = if legacy
        self::LegacyTracer
      else
        self::Tracer
      end
      schema_defn.tracer(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

    # Used for internal bookkeeping
    # @api private
    class Frame
      attr_reader :path, :query, :ast_node, :object, :field, :arguments, :parent_frame
      def initialize(path:, query:, ast_node:, object:, field:, arguments:, parent_frame:)
        @path = path
        @query = query
        @ast_node = ast_node
        @field = field
        @object = object
        @arguments = arguments
        @parent_frame = parent_frame
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
graphql-1.13.23 lib/graphql/backtrace.rb
graphql-1.13.22 lib/graphql/backtrace.rb
graphql-1.13.21 lib/graphql/backtrace.rb
graphql-1.13.20 lib/graphql/backtrace.rb
graphql-1.13.19 lib/graphql/backtrace.rb
graphql-1.13.18 lib/graphql/backtrace.rb
graphql-1.13.17 lib/graphql/backtrace.rb
graphql-1.13.16 lib/graphql/backtrace.rb
graphql-1.13.15 lib/graphql/backtrace.rb
graphql-1.13.14 lib/graphql/backtrace.rb
graphql-1.13.13 lib/graphql/backtrace.rb
graphql_cody-1.13.0 lib/graphql/backtrace.rb
graphql-1.13.12 lib/graphql/backtrace.rb
graphql-1.13.11 lib/graphql/backtrace.rb
graphql-1.13.10 lib/graphql/backtrace.rb
graphql-1.13.9 lib/graphql/backtrace.rb
graphql-1.12.24 lib/graphql/backtrace.rb
graphql-1.13.8 lib/graphql/backtrace.rb
graphql-1.13.7 lib/graphql/backtrace.rb
graphql-1.13.6 lib/graphql/backtrace.rb