Skip to content

Commit f03f600

Browse files
committed
don't trim comment lines for description
1 parent ea5f959 commit f03f600

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/main/java/graphql/schema/idl/SchemaGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ private String buildDescription(Node node) {
523523
List<Comment> comments = node.getComments();
524524
List<String> lines = new ArrayList<>();
525525
for (int i = 0; i < comments.size(); i++) {
526-
String commentLine = comments.get(i).getContent().trim();
527-
if (commentLine.isEmpty()) {
526+
String commentLine = comments.get(i).getContent();
527+
if (commentLine.trim().isEmpty()) {
528528
lines.clear();
529529
} else {
530530
lines.add(commentLine);

src/test/groovy/graphql/schema/idl/SchemaGeneratorTest.groovy

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SchemaGeneratorTest extends Specification {
6767

6868
def authorField = schema.getQueryType().getFieldDefinition("author")
6969
assert authorField.type.name == "Author"
70-
assert authorField.description == "author query must receive an id as argument"
70+
assert authorField.description == " author query must receive an id as argument"
7171
assert authorField.arguments.get(0).name == "id"
7272
assert authorField.arguments.get(0).type instanceof GraphQLNonNull
7373
assert unwrap(authorField.arguments.get(0).type).name == "Int"
@@ -125,7 +125,7 @@ class SchemaGeneratorTest extends Specification {
125125
assert (unwrap(upvotePostFieldArg.type) as GraphQLInputObjectType).getField("votes").type.name == "Int"
126126

127127
def queryType = schema.getQueryType()
128-
assert queryType.description == "the schema allows the following query\nto be made"
128+
assert queryType.description == " the schema allows the following query\n to be made"
129129

130130
}
131131

@@ -702,7 +702,7 @@ class SchemaGeneratorTest extends Specification {
702702
def "comments are used as descriptions"() {
703703
given:
704704
def spec = """
705-
# description 1
705+
#description 1
706706
# description 2
707707
type Query {
708708
# description 3
@@ -741,18 +741,18 @@ class SchemaGeneratorTest extends Specification {
741741
def schema = generateSchema(spec, wiring)
742742

743743
then:
744-
schema.getQueryType().description == "description 1\ndescription 2"
745-
schema.getQueryType().getFieldDefinition("foo").description == "description 3"
746-
((GraphQLUnionType) schema.getType("Union")).description == "description 4"
744+
schema.getQueryType().description == "description 1\n description 2"
745+
schema.getQueryType().getFieldDefinition("foo").description == " description 3"
746+
((GraphQLUnionType) schema.getType("Union")).description == " description 4"
747747

748-
((GraphQLInterfaceType) schema.getType("Interface")).description == "description 5"
749-
((GraphQLInterfaceType) schema.getType("Interface")).getFieldDefinition("foo").description == "interface field"
748+
((GraphQLInterfaceType) schema.getType("Interface")).description == " description 5"
749+
((GraphQLInterfaceType) schema.getType("Interface")).getFieldDefinition("foo").description == " interface field"
750750

751-
((GraphQLInputObjectType) schema.getType("Input")).description == "description 6"
752-
((GraphQLInputObjectType) schema.getType("Input")).getFieldDefinition("foo").description == "input field"
751+
((GraphQLInputObjectType) schema.getType("Input")).description == " description 6 "
752+
((GraphQLInputObjectType) schema.getType("Input")).getFieldDefinition("foo").description == " input field"
753753

754-
((GraphQLEnumType) schema.getType("Enum")).description == "description 7"
755-
((GraphQLEnumType) schema.getType("Enum")).getValue("FOO").description == "enum value"
754+
((GraphQLEnumType) schema.getType("Enum")).description == " description 7"
755+
((GraphQLEnumType) schema.getType("Enum")).getValue("FOO").description == " enum value"
756756
}
757757

758758
def "comments are separated from descriptions with empty lines"() {
@@ -788,7 +788,7 @@ class SchemaGeneratorTest extends Specification {
788788
def schema = generateSchema(spec, wiring)
789789

790790
then:
791-
schema.getQueryType().description == "description 1\ndescription 2"
792-
schema.getQueryType().getFieldDefinition("foo").description == "description 3\ndescription 4"
791+
schema.getQueryType().description == " description 1\n description 2"
792+
schema.getQueryType().getFieldDefinition("foo").description == " description 3\n description 4"
793793
}
794794
}

0 commit comments

Comments
 (0)