Skip to content

Commit

Permalink
Fix printing of ASTs of argument definitions with descriptions.
Browse files Browse the repository at this point in the history
Descriptions were not separated on their own lines, which made for technically parseable but hard to read output.

Fixes #1285
  • Loading branch information
leebyron committed Mar 29, 2018
1 parent 433774d commit 16ac5fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/language/__tests__/schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/language/__tests__/schema-printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ describe('Printer: SDL document', () => {
"""
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
Expand Down
8 changes: 6 additions & 2 deletions src/language/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ const printDocASTReducer = {
FieldDefinition: addDescription(
({ name, arguments: args, type, directives }) =>
name +
wrap('(', join(args, ', '), ')') +
(args.every(arg => arg.indexOf('\n') === -1)
? wrap('(', join(args, ', '), ')')
: wrap('(\n', indent(join(args, '\n')), '\n)')) +
': ' +
type +
wrap(' ', join(directives, ' ')),
Expand Down Expand Up @@ -212,7 +214,9 @@ const printDocASTReducer = {
({ name, arguments: args, locations }) =>
'directive @' +
name +
wrap('(', join(args, ', '), ')') +
(args.every(arg => arg.indexOf('\n') === -1)
? wrap('(', join(args, ', '), ')')
: wrap('(\n', indent(join(args, '\n')), '\n)')) +
' on ' +
join(locations, ' | '),
),
Expand Down

0 comments on commit 16ac5fa

Please sign in to comment.