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.



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

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



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

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



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

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