class GraphQL::Language::Printer
Constants
- OMISSION
Public Instance Methods
# File lib/graphql/language/printer.rb, line 69 def print(node, indent: "", truncate_size: nil) truncate_size = truncate_size ? [truncate_size - OMISSION.size, 0].max : nil @out = TruncatableBuffer.new(truncate_size: truncate_size) print_node(node, indent: indent) @out.to_string rescue TruncatableBuffer::TruncateSizeReached @out.to_string << OMISSION end
Turn an arbitrary AST node back into a string.
Examples
Example: Turning a document into a query string
document = GraphQL.parse(query_string) GraphQL::Language::Printer.new.print(document) # => "{ ... }"
Example: Building a custom printer
class MyPrinter < GraphQL::Language::Printer def print_argument(arg) print_string("#{arg.name}: <HIDDEN>") end end MyPrinter.new.print(document) # => "mutation { pay(creditCard: <HIDDEN>) { success } }"
Parameters
-
node(Nodes::AbstractNode) -
indent(String) — Whitespace to add to the printed node -
truncate_size(Integer, nil) — The size to truncate to.
Returns
-
String— ValidGraphQLfornode