mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-21 20:36:05 +03:00
Fix printing of ASTs of argument definitions with descriptions
This commit is contained in:
parent
25cfebbd37
commit
b4be42acdf
@ -263,8 +263,14 @@ class Printer
|
||||
}),
|
||||
|
||||
NodeKind::FIELD_DEFINITION => $this->addDescription(function (FieldDefinitionNode $def) {
|
||||
$noIndent = Utils::every($def->arguments, static function (string $arg) {
|
||||
return strpos($arg, "\n") === false;
|
||||
});
|
||||
|
||||
return $def->name
|
||||
. $this->wrap('(', $this->join($def->arguments, ', '), ')')
|
||||
. ($noIndent
|
||||
? $this->wrap('(', $this->join($def->arguments, ', '), ')')
|
||||
: $this->wrap("(\n", $this->indent($this->join($def->arguments, "\n")), "\n)"))
|
||||
. ': ' . $def->type
|
||||
. $this->wrap(' ', $this->join($def->directives, ' '));
|
||||
}),
|
||||
@ -424,9 +430,15 @@ class Printer
|
||||
},
|
||||
|
||||
NodeKind::DIRECTIVE_DEFINITION => $this->addDescription(function (DirectiveDefinitionNode $def) {
|
||||
$noIndent = Utils::every($def->arguments, static function (string $arg) {
|
||||
return strpos($arg, "\n") === false;
|
||||
});
|
||||
|
||||
return 'directive @'
|
||||
. $def->name
|
||||
. $this->wrap('(', $this->join($def->arguments, ', '), ')')
|
||||
. ($noIndent
|
||||
? $this->wrap('(', $this->join($def->arguments, ', '), ')')
|
||||
: $this->wrap("(\n", $this->indent($this->join($def->arguments, "\n")), "\n"))
|
||||
. ' on ' . $this->join($def->locations, ' | ');
|
||||
}),
|
||||
],
|
||||
|
@ -52,6 +52,9 @@ class SchemaPrinterTest extends TestCase
|
||||
self::assertEquals($astCopy, $ast);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('prints kitchen sink')
|
||||
*/
|
||||
public function testPrintsKitchenSink() : void
|
||||
{
|
||||
$kitchenSink = file_get_contents(__DIR__ . '/schema-kitchen-sink.graphql');
|
||||
@ -70,7 +73,15 @@ of the `Foo` type.
|
||||
"""
|
||||
type Foo implements Bar & Baz {
|
||||
one: Type
|
||||
two(argument: InputType!): Type
|
||||
"""
|
||||
This is a description of the `two` field.
|
||||
"""
|
||||
two(
|
||||
"""
|
||||
This is a description of the `argument` argument.
|
||||
"""
|
||||
argument: InputType!
|
||||
): Type
|
||||
three(argument: InputType, other: String): Int
|
||||
four(argument: String = "string"): String
|
||||
five(argument: [String] = ["string", "string"]): String
|
||||
|
@ -14,7 +14,15 @@ of the `Foo` type.
|
||||
"""
|
||||
type Foo implements Bar & Baz {
|
||||
one: Type
|
||||
two(argument: InputType!): Type
|
||||
"""
|
||||
This is a description of the `two` field.
|
||||
"""
|
||||
two(
|
||||
"""
|
||||
This is a description of the `argument` argument.
|
||||
"""
|
||||
argument: InputType!
|
||||
): Type
|
||||
three(argument: InputType, other: String): Int
|
||||
four(argument: String = "string"): String
|
||||
five(argument: [String] = ["string", "string"]): String
|
||||
|
Loading…
Reference in New Issue
Block a user