Skip to content

Commit 43fb385

Browse files
author
Tom Groves
committed
Default schema description to null when not provided
1 parent 5ee7999 commit 43fb385

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/main/kotlin/graphql/kickstart/tools/RootTypeInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class RootTypeInfo private constructor(
1717
const val DEFAULT_QUERY_NAME = "Query"
1818
const val DEFAULT_MUTATION_NAME = "Mutation"
1919
const val DEFAULT_SUBSCRIPTION_NAME = "Subscription"
20-
const val DEFAULT_DESCRIPTION = "A GraphQL schema provides a root type for each kind of operation."
20+
val DEFAULT_DESCRIPTION: String? = null // According to the GraphQL Specification description should be a string or `null`
2121

2222
fun fromSchemaDefinitions(definitions: List<SchemaDefinition>): RootTypeInfo {
2323
val queryType = definitions.lastOrNull()?.operationTypeDefinitions?.find { it.name == "query" }?.typeName

src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class SchemaParserTest {
575575
}
576576

577577
@Test
578-
fun `parser should include schema descriptions`() {
578+
fun `parser should include schema descriptions when declared`() {
579579
val schema = SchemaParser.newParser()
580580
.schemaString(
581581
"""
@@ -600,6 +600,31 @@ class SchemaParserTest {
600600
assertEquals(schema.description, "This is a schema level description")
601601
}
602602

603+
@Test
604+
fun `parser should return null schema description when not declared`() {
605+
val schema = SchemaParser.newParser()
606+
.schemaString(
607+
"""
608+
schema {
609+
query: SubstituteQuery
610+
}
611+
612+
type SubstituteQuery {
613+
description: String
614+
comment: String
615+
omitted: String
616+
both: String
617+
empty: String
618+
}
619+
""")
620+
.resolvers(object : GraphQLQueryResolver {})
621+
.options(SchemaParserOptions.newOptions().allowUnimplementedResolvers(true).build())
622+
.build()
623+
.makeExecutableSchema()
624+
625+
assertNull(schema.description)
626+
}
627+
603628
enum class EnumType {
604629
TEST
605630
}

0 commit comments

Comments
 (0)