Skip to content

Commit 656f4e3

Browse files
authored
Fix AstPrinter throws on empty description (graphql-java#2281)
Fix graphql-java#2151
1 parent 1d16e70 commit 656f4e3

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/main/java/graphql/language/AstPrinter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private String description(Node<?> node) {
505505
return "";
506506
}
507507
String s;
508-
boolean startNewLine = description.getContent().charAt(0) == '\n';
508+
boolean startNewLine = description.getContent().length() > 0 && description.getContent().charAt(0) == '\n';
509509
if (description.isMultiLine()) {
510510
s = "\"\"\"" + (startNewLine ? "" : "\n") + description.getContent() + "\n\"\"\"\n";
511511
} else {

src/test/groovy/graphql/language/AstPrinterTest.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,20 @@ type Query {
452452

453453
}
454454

455+
def "print empty description"() {
456+
def query = '''
457+
""
458+
scalar Demo
459+
'''
460+
def document = parse(query)
461+
String output = printAst(document)
462+
463+
expect:
464+
output == '''""
465+
scalar Demo
466+
'''
467+
}
468+
455469
def "print type extensions"() {
456470
def query = '''
457471
extend schema {

0 commit comments

Comments
 (0)