Skip to content

Commit 2e1becb

Browse files
printSchema: support empty descriptions (#2177)
1 parent c673035 commit 2e1becb

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Diff for: src/utilities/__tests__/schemaPrinter-test.js

+14
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,20 @@ describe('Type System Printer', () => {
483483
`);
484484
});
485485

486+
it('Prints an empty description', () => {
487+
const output = printSingleFieldSchema({
488+
type: GraphQLString,
489+
description: '',
490+
});
491+
492+
expect(output).to.equal(dedent`
493+
type Query {
494+
""""""
495+
singleField: String
496+
}
497+
`);
498+
});
499+
486500
it('One-line prints a short description', () => {
487501
const description = 'This field is awesome';
488502
const output = printSingleFieldSchema({

Diff for: src/utilities/buildASTSchema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function getLeadingCommentBlock(node): void | string {
475475
comments.push(value);
476476
token = token.prev;
477477
}
478-
return comments.reverse().join('\n');
478+
return comments.length > 0 ? comments.reverse().join('\n') : undefined;
479479
}
480480

481481
/**

Diff for: src/utilities/schemaPrinter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function printDescription(
317317
indentation = '',
318318
firstInBlock = true,
319319
): string {
320-
if (!def.description) {
320+
if (def.description == null) {
321321
return '';
322322
}
323323

0 commit comments

Comments
 (0)