Skip to content

Latest commit

 

History

History
319 lines (127 loc) · 3.49 KB

Printer.md

File metadata and controls

319 lines (127 loc) · 3.49 KB

Printer

Prints AST to string. Capable of printing GraphQL queries and Type definition language.

Useful for pretty-printing queries or printing back AST for logging, documentation, etc.

Usage example:

$query = 'query myQuery {someField}';
$ast = GraphQL\Language\Parser::parse($query);
$printed = GraphQL\Language\Printer::doPrint($ast);
  • Full name: \GraphQL\Language\Printer

Methods

doPrint

Prints AST to string. Capable of printing GraphQL queries and Type definition language.

public static doPrint(\GraphQL\Language\AST\Node $ast): string
  • This method is static.

Parameters:

Parameter Type Description
$ast \GraphQL\Language\AST\Node

__construct

protected __construct(): mixed

printAST

Traverse an AST bottom-up, converting all nodes to strings.

public printAST(mixed $ast): mixed

That means the AST is manipulated in such a way that it no longer resembles the well-formed result of parsing.

Parameters:

Parameter Type Description
$ast mixed

addDescription

public addDescription(callable $cb): mixed

Parameters:

Parameter Type Description
$cb callable

wrap

If maybeString is not null or empty, then wrap with start and end, otherwise print an empty string.

public wrap(mixed $start, mixed $maybeString, mixed $end = ''): mixed

Parameters:

Parameter Type Description
$start mixed
$maybeString mixed
$end mixed

block

Given array, print each item on its own line, wrapped in an indented "{ }" block.

public block(mixed $array): mixed

Parameters:

Parameter Type Description
$array mixed

indent

public indent(mixed $maybeString): mixed

Parameters:

Parameter Type Description
$maybeString mixed

manyList

public manyList(mixed $start, mixed $list, mixed $separator, mixed $end): mixed

Parameters:

Parameter Type Description
$start mixed
$list mixed
$separator mixed
$end mixed

length

public length(mixed $maybeArray): mixed

Parameters:

Parameter Type Description
$maybeArray mixed

join

public join(mixed $maybeArray, mixed $separator = ''): string

Parameters:

Parameter Type Description
$maybeArray mixed
$separator mixed

printBlockString

Print a block string in the indented block form by adding a leading and trailing blank line. However, if a block string starts with whitespace and is a single-line, adding a leading blank line would strip that whitespace.

private printBlockString(mixed $value, mixed $isDescription): mixed

Parameters:

Parameter Type Description
$value mixed
$isDescription mixed