Class: GraphQL::Backtrace::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/backtrace/table.rb

Overview

A class for turning a context into a human-readable table or array

Constant Summary collapse

MIN_COL_WIDTH =
4
MAX_COL_WIDTH =
100
HEADERS =
[
  "Loc",
  "Field",
  "Object",
  "Arguments",
  "Result",
]

Instance Method Summary collapse

Constructor Details

#initialize(context, value:) ⇒ Table

Returns a new instance of Table



17
18
19
20
# File 'lib/graphql/backtrace/table.rb', line 17

def initialize(context, value:)
  @context = context
  @override_value = value
end

Instance Method Details

#to_backtraceArray<String>

Returns An array of position + field name entries

Returns:

  • (Array<String>)

    An array of position + field name entries



28
29
30
31
32
33
34
35
# File 'lib/graphql/backtrace/table.rb', line 28

def to_backtrace
  @to_backtrace ||= begin
    backtrace = rows.map { |r| "#{r[0]}: #{r[1]}" }
    # skip the header entry
    backtrace.shift
    backtrace
  end
end

#to_tableString

Returns A table layout of backtrace with metadata

Returns:

  • (String)

    A table layout of backtrace with metadata



23
24
25
# File 'lib/graphql/backtrace/table.rb', line 23

def to_table
  @to_table ||= render_table(rows)
end