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 ''; }