diff --git a/src/main/java/graphql/language/AstPrinter.java b/src/main/java/graphql/language/AstPrinter.java index 1567162588..8d15854637 100644 --- a/src/main/java/graphql/language/AstPrinter.java +++ b/src/main/java/graphql/language/AstPrinter.java @@ -163,7 +163,7 @@ private NodePrinter fieldDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { String args; - if (hasDescription(node.getInputValueDefinitions()) && !compactMode) { + if (hasDescription(Collections.singletonList(node)) && !compactMode) { out.append(description(node)); args = join(node.getInputValueDefinitions(), "\n"); out.append(node.getName()) diff --git a/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy b/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy index 2b687e77e6..82c38ce42d 100644 --- a/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy +++ b/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy @@ -104,13 +104,11 @@ class IntrospectionResultToSchemaTest extends Specification { then: result == """type QueryType implements Query { - hero( - \"\"\" + hero(\"\"\" comment about episode on two lines \"\"\" - episode: Episode - foo: String = \"bar\"): Character @deprecated(reason: "killed off character") + episode: Episode, foo: String = \"bar\"): Character @deprecated(reason: "killed off character") }""" } @@ -212,9 +210,13 @@ class IntrospectionResultToSchemaTest extends Specification { then: result == """"A character in the Star Wars Trilogy" interface Character { + "The id of the character." id: String! + "The name of the character." name: String + "The friends of the character, or an empty list if they have none." friends: [Character] + "Which movies they appear in." appearsIn: [Episode] }""" @@ -407,22 +409,23 @@ input CharacterInput { } type QueryType { - hero( - "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode." + hero("If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode." episode: Episode): Character - human( - "id of the human" + human("id of the human" id: String!): Human - droid( - "id of the droid" + droid("id of the droid" id: String!): Droid } "A character in the Star Wars Trilogy" interface Character { + "The id of the character." id: String! + "The name of the character." name: String + "The friends of the character, or an empty list if they have none." friends: [Character] + "Which movies they appear in." appearsIn: [Episode] } @@ -438,19 +441,29 @@ enum Episode { "A humanoid creature in the Star Wars universe." type Human implements Character { + "The id of the human." id: String! + "The name of the human." name: String + "The friends of the human, or an empty list if they have none." friends: [Character] + "Which movies they appear in." appearsIn: [Episode] + "The home planet of the human, or null if unknown." homePlanet: String } "A mechanical creature in the Star Wars universe." type Droid implements Character { + "The id of the droid." id: String! + "The name of the droid." name: String + "The friends of the droid, or an empty list if they have none." friends: [Character] + "Which movies they appear in." appearsIn: [Episode] + "The primary function of the droid." primaryFunction: String } """ @@ -975,4 +988,4 @@ scalar EmployeeRef scalar EmployeeRef ''' } -} \ No newline at end of file +} diff --git a/src/test/groovy/graphql/language/AstPrinterTest.groovy b/src/test/groovy/graphql/language/AstPrinterTest.groovy index bb7024e8b6..54e5eb2d90 100644 --- a/src/test/groovy/graphql/language/AstPrinterTest.groovy +++ b/src/test/groovy/graphql/language/AstPrinterTest.groovy @@ -472,6 +472,26 @@ type Query { } + def "print field descriptions"() { + def query = '''type Query { + "description" + field( + "description" + a: String): String +} +''' + def document = parse(query) + String output = printAst(document) + expect: + output == '''type Query { + "description" + field( + "description" + a: String): String +} +''' + } + def "print empty description"() { def query = ''' ""