Class: GraphQL::Language::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/language/printer.rb

Instance Method Summary collapse

Instance Method Details

Turn an arbitrary AST node back into a string.

Examples:

Turning a document into a query string

document = GraphQL.parse(query_string)
GraphQL::Language::Printer.new.print(document)
# => "{ ... }"

Building a custom printer


class MyPrinter < GraphQL::Language::Printer
  def print_argument(arg)
    "#{arg.name}: <HIDDEN>"
  end
end

MyPrinter.new.print(document)
# => "mutation { pay(creditCard: <HIDDEN>) { success } }"

Parameters:

  • indent (String)

    Whitespace to add to the printed node

Returns:

  • (String)

    Valid GraphQL for node



27
28
29
# File 'lib/graphql/language/printer.rb', line 27

def print(node, indent: "")
  print_node(node, indent: indent)
end