Skip to main content
Version: pre-release

Maven Plugin SDL Usage

GraphQL Kotlin follows a code-first approach where schema is auto generated from your source code at runtime. GraphQL Kotlin plugins can be used to generate schema as a build time artifact. This allows you to seamlessly integrate with various GraphQL tools that may require a schema artifact as an input (e.g. to perform backwards compatibility checks, etc).

Generating SDL

GraphQL schema can be generated directly from your source code using reflections. generate-sdl mojo will scan your classpath looking for classes implementing Query, Mutation and Subscription marker interfaces and then generates the corresponding GraphQL schema using graphql-kotlin-schema-generator and default NoopSchemaGeneratorHooks. In order to limit the amount of packages to scan, this mojo requires users to provide a list of packages that can contain GraphQL types.

<plugin>
<groupId>com.expediagroup</groupId>
<artifactId>graphql-kotlin-maven-plugin</artifactId>
<version>${graphql-kotlin.version}</version>
<executions>
<execution>
<goals>
<goal>generate-sdl</goal>
</goals>
<configuration>
<packages>
<package>com.example</package>
</packages>
</configuration>
</execution>
</executions>
</plugin>

Using Custom Hooks Provider

Plugin will default to use NoopSchemaGeneratorHooks to generate target GraphQL schema. If your project uses custom hooks or needs to generate the federated GraphQL schema, you will need to provide an instance of SchemaGeneratorHooksProvider service provider that will be used to create an instance of your custom hooks.

generate-sdl mojo utilizes ServiceLoader mechanism to dynamically load available SchemaGeneratorHooksProvider service providers from the classpath. Service provider can be provided as part of your project, included in one of your project dependencies or through explicitly provided artifact. See Schema Generator Hooks Provider for additional details on how to create custom hooks service provider. Configuration below shows how to configure GraphQL Kotlin plugin with explicitly provided artifact to generate federated GraphQL schema.

<plugin>
<groupId>com.expediagroup</groupId>
<artifactId>graphql-kotlin-maven-plugin</artifactId>
<version>${graphql-kotlin.version}</version>
<executions>
<execution>
<goals>
<goal>generate-sdl</goal>
</goals>
<configuration>
<packages>
<package>com.example</package>
</packages>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.expediagroup</groupId>
<artifactId>graphql-kotlin-federated-hooks-provider</artifactId>
<version>${graphql-kotlin.version}</version>
</dependency>
</dependencies>
</plugin>