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
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 |
protected __construct(): mixed
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 |
public addDescription(callable $cb): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$cb |
callable |
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 |
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 |
public indent(mixed $maybeString): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$maybeString |
mixed |
public manyList(mixed $start, mixed $list, mixed $separator, mixed $end): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$start |
mixed | |
$list |
mixed | |
$separator |
mixed | |
$end |
mixed |
public length(mixed $maybeArray): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$maybeArray |
mixed |
public join(mixed $maybeArray, mixed $separator = ''): string
Parameters:
Parameter | Type | Description |
---|---|---|
$maybeArray |
mixed | |
$separator |
mixed |
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 |