Skip to main content
Version: pre-release


Schema Object

SchemaGenerator automatically generates schema object from the provided list of TopLevelObjects representing queries, mutations and subscriptions.

In order to provide schema description or to specify schema directives, we need to provide TopLevelObject reference to a schema class.


Only annotations are processed on the schema object. Generator will throw an exception if schema class contains any properties or functions.

In the example below, we provide custom description and apply @contact directive on the schema object.

name = "My Team Name",
url = "",
description = "send urgent issues to [#oncall]("
@GraphQLDescription("My schema description")
class MySchema

class HelloWorldQuery {
fun helloWorld() = "Hello World!"

// generate schema
val schema = toSchema(
config = yourCustomConfig(),
queries = listOf(TopLevelObject(HelloWorldQuery())),
schemaObject = TopLevelObject(MySchema())

Will generate

schema @contact(description : "send urgent issues to [#oncall](", name : "My Team Name", url : ""){
query: Query

type Query {
helloWorld: String!

graphql-java currently does not include schema description in the generated SDL (it is available in the introspection results only). Fixed in