Skip to content

Commit 16ac5fa

Browse files
committed
Fix printing of ASTs of argument definitions with descriptions.
Descriptions were not separated on their own lines, which made for technically parseable but hard to read output. Fixes #1285
1 parent 433774d commit 16ac5fa

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/language/__tests__/schema-kitchen-sink.graphql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ of the `Foo` type.
1414
"""
1515
type Foo implements Bar & Baz {
1616
one: Type
17-
two(argument: InputType!): Type
17+
"""
18+
This is a description of the `two` field.
19+
"""
20+
two(
21+
"""
22+
This is a description of the `argument` argument.
23+
"""
24+
argument: InputType!
25+
): Type
1826
three(argument: InputType, other: String): Int
1927
four(argument: String = "string"): String
2028
five(argument: [String] = ["string", "string"]): String

src/language/__tests__/schema-printer-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ describe('Printer: SDL document', () => {
5858
"""
5959
type Foo implements Bar & Baz {
6060
one: Type
61-
two(argument: InputType!): Type
61+
"""
62+
This is a description of the \`two\` field.
63+
"""
64+
two(
65+
"""
66+
This is a description of the \`argument\` argument.
67+
"""
68+
argument: InputType!
69+
): Type
6270
three(argument: InputType, other: String): Int
6371
four(argument: String = "string"): String
6472
five(argument: [String] = ["string", "string"]): String

src/language/printer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ const printDocASTReducer = {
131131
FieldDefinition: addDescription(
132132
({ name, arguments: args, type, directives }) =>
133133
name +
134-
wrap('(', join(args, ', '), ')') +
134+
(args.every(arg => arg.indexOf('\n') === -1)
135+
? wrap('(', join(args, ', '), ')')
136+
: wrap('(\n', indent(join(args, '\n')), '\n)')) +
135137
': ' +
136138
type +
137139
wrap(' ', join(directives, ' ')),
@@ -212,7 +214,9 @@ const printDocASTReducer = {
212214
({ name, arguments: args, locations }) =>
213215
'directive @' +
214216
name +
215-
wrap('(', join(args, ', '), ')') +
217+
(args.every(arg => arg.indexOf('\n') === -1)
218+
? wrap('(', join(args, ', '), ')')
219+
: wrap('(\n', indent(join(args, '\n')), '\n)')) +
216220
' on ' +
217221
join(locations, ' | '),
218222
),

0 commit comments

Comments
 (0)