Module: GraphQL::Language::Generation

Extended by:
Generation
Included in:
Generation
Defined in:
lib/graphql/language/generation.rb

Overview

Exposes #generate, which turns AST nodes back into query strings.

Instance Method Summary collapse

Instance Method Details

#generate(node, indent: "", printer: GraphQL::Language::Printer.new) ⇒ String

Turn an AST node back into a string.

Examples:

Turning a document into a query

document = GraphQL.parse(query_string)
GraphQL::Language::Generation.generate(document)
# => "{ ... }"

Parameters:

  • node (GraphQL::Language::Nodes::AbstractNode)

    an AST node to recursively stringify

  • indent (String) (defaults to: "")

    Whitespace to add to each printed node

  • printer (GraphQL::Language::Printer) (defaults to: GraphQL::Language::Printer.new)

    An optional custom printer for printing AST nodes. Defaults to GraphQL::Language::Printer

Returns:

  • (String)

    Valid GraphQL for node



19
20
21
# File 'lib/graphql/language/generation.rb', line 19

def generate(node, indent: "", printer: GraphQL::Language::Printer.new)
  printer.print(node, indent: indent)
end