GraphQL Kotlin plugins can generate GraphQL schema as your build artifact directly from your source code. Plugins will scan
your classpath for classes implementing
and then generate corresponding GraphQL schema using
graphql-kotlin-schema-generator. By default, plugins will generate
the schema using
NoopSchemaGeneratorHooks. If your project uses custom hooks or needs to generate the federated GraphQL
schema, you will need to provide an instance of
SchemaGeneratorHooksProvider that will be used to create an instance of
your custom hooks.
SchemaGeneratorHooksProvider is a service provider interface that exposes a single
hooks method to generate an instance
SchemaGeneratorHooks that will be used to generate your schema. By utilizing Java ServiceLoader
we can dynamically load your custom provider from the classpath. Service provider can be provided as part of your project
sources, included inside of one of your project dependencies or through explicitly provided artifact. Since we need to be
able to deterministically choose a single hooks provider, generation of schema will fail if there are multiple providers
on the classpath.
SchemaGeneratorHooksProvider interface is defined in
Service provider implementation has to implement
SchemaGeneratorHooksProvider interface that provides a way to instantiate
schema generator hooks that will be used to generate the GraphQL schema.
Service loader provider configuration file should be created under JAR
/META-INF/services directory (e.g.
in default project structure). Name of the provider configuration should be fully qualified service provider interface name, i.e.
com.expediagroup.graphql.plugin.schema.hooks.SchemaGeneratorHooksProvider and contain single entry - a fully qualified
name of the service provider implementation.
Using the example service provider implementation from the above, our project structure should look like
Our service provider configuration file should have following content
We don't support Java 9 module mechanism for declaring
ServiceLoader implementations. As a workaround, you have to define
your service providers in the provider configuration file under