From 0b551ec8207d4ac9913e5999521d35f94c21cf05 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 16 Sep 2019 16:33:29 +0300 Subject: [PATCH] printSchema: support empty descriptions --- src/utilities/__tests__/schemaPrinter-test.js | 14 ++++++++++++++ src/utilities/buildASTSchema.js | 2 +- src/utilities/schemaPrinter.js | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/utilities/__tests__/schemaPrinter-test.js b/src/utilities/__tests__/schemaPrinter-test.js index 850e47f94f..5f82f097db 100644 --- a/src/utilities/__tests__/schemaPrinter-test.js +++ b/src/utilities/__tests__/schemaPrinter-test.js @@ -483,6 +483,20 @@ describe('Type System Printer', () => { `); }); + it('Prints an empty description', () => { + const output = printSingleFieldSchema({ + type: GraphQLString, + description: '', + }); + + expect(output).to.equal(dedent` + type Query { + """""" + singleField: String + } + `); + }); + it('One-line prints a short description', () => { const description = 'This field is awesome'; const output = printSingleFieldSchema({ diff --git a/src/utilities/buildASTSchema.js b/src/utilities/buildASTSchema.js index 3f0ed0d7ff..6b7951144e 100644 --- a/src/utilities/buildASTSchema.js +++ b/src/utilities/buildASTSchema.js @@ -475,7 +475,7 @@ function getLeadingCommentBlock(node): void | string { comments.push(value); token = token.prev; } - return comments.reverse().join('\n'); + return comments.length > 0 ? comments.reverse().join('\n') : undefined; } /** diff --git a/src/utilities/schemaPrinter.js b/src/utilities/schemaPrinter.js index 6d50a62e5e..8b9e863ef7 100644 --- a/src/utilities/schemaPrinter.js +++ b/src/utilities/schemaPrinter.js @@ -317,7 +317,7 @@ function printDescription( indentation = '', firstInBlock = true, ): string { - if (!def.description) { + if (def.description == null) { return ''; }