Sha256: 3a37520b66584bee8c09abc903651de07a01bf826017f6c1856dffae20adb518

Contents?: true

Size: 1.46 KB

Versions: 62

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true
require "graphql/backtrace/inspect_result"
require "graphql/backtrace/table"
require "graphql/backtrace/traced_error"
require "graphql/backtrace/tracer"
require "graphql/backtrace/trace"
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.trace_with(self::Trace)
    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

62 entries across 62 versions & 1 rubygems

Version Path
graphql-2.4.4 lib/graphql/backtrace.rb
graphql-2.4.3 lib/graphql/backtrace.rb
graphql-2.4.2 lib/graphql/backtrace.rb
graphql-2.4.1 lib/graphql/backtrace.rb
graphql-2.4.0 lib/graphql/backtrace.rb
graphql-2.3.20 lib/graphql/backtrace.rb
graphql-2.3.19 lib/graphql/backtrace.rb
graphql-2.3.18 lib/graphql/backtrace.rb
graphql-2.3.17 lib/graphql/backtrace.rb
graphql-2.3.16 lib/graphql/backtrace.rb
graphql-2.3.15 lib/graphql/backtrace.rb
graphql-2.3.14 lib/graphql/backtrace.rb
graphql-2.3.13 lib/graphql/backtrace.rb
graphql-2.3.12 lib/graphql/backtrace.rb
graphql-2.3.11 lib/graphql/backtrace.rb
graphql-2.3.10 lib/graphql/backtrace.rb
graphql-2.2.16 lib/graphql/backtrace.rb
graphql-2.1.13 lib/graphql/backtrace.rb
graphql-2.3.9 lib/graphql/backtrace.rb
graphql-2.3.8 lib/graphql/backtrace.rb