diff --git a/src/Language/Printer.php b/src/Language/Printer.php index 891f411..ff11d50 100644 --- a/src/Language/Printer.php +++ b/src/Language/Printer.php @@ -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, ' | '); }), ], diff --git a/tests/Language/SchemaPrinterTest.php b/tests/Language/SchemaPrinterTest.php index 3a07677..b576983 100644 --- a/tests/Language/SchemaPrinterTest.php +++ b/tests/Language/SchemaPrinterTest.php @@ -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 diff --git a/tests/Language/schema-kitchen-sink.graphql b/tests/Language/schema-kitchen-sink.graphql index 6ca3c59..3ad830c 100644 --- a/tests/Language/schema-kitchen-sink.graphql +++ b/tests/Language/schema-kitchen-sink.graphql @@ -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