To use this plugin to generate a schema for use with SangriaCodegenPlugin
they must be configured in separate projects. For example, SangriaSchemagenPlugin
could be enabled in the server project which defines the Sangria schema, and
SangriaCodegenPlugin will be enabled in the client project which consumes
the GraphQL services.
The plugins introduces a parallel build scope named sangria-schemagen and
uses it for generating a program for executing the schema introspection code
defined in sangriaSchemagenSnippet. The build scope depends on the normal
compile scope so schema classes are available when running the program.
Generate code can be found in target/scala-2.x/src_managed/sangria-schemagen
and compile artifacts can be found in target/scala-2.x/sangria-schemagen-classes.
sangriaSchemagenSnippet: Code snippet to access the Sangria Schema.
sangriaSchemagenSchema: GraphQL schema output file. Defaults to
file located inside resourceManaged.
sangriaSchemagen: Generate the GraphQL schema file.
Example:
sangriaSchemagenSnippet in Compile := Some("com.example.schema.GraphqlSchema")
sangriaSchemagenSchema in Compile := (resourceDirectory in Compile).value / "schema.graphql"
Linear Supertypes
AutoPlugin, PluginsFunctions, Basic, Plugins, AnyRef, Any
Generate GraphQL schema file from a Sangria schema instance.
Usage
This plugin must be explicitly enabled. To enable it add the following line to your
.sbt
file:In addition, it is required to configure
sangriaSchemagenSnippet
with a snippet of Scala code providing access to yoursangria.schema.Schema[_, _]
.See the example project.
Using with SangriaCodegenPlugin
To use this plugin to generate a schema for use with SangriaCodegenPlugin they must be configured in separate projects. For example, SangriaSchemagenPlugin could be enabled in the server project which defines the Sangria schema, and SangriaCodegenPlugin will be enabled in the client project which consumes the GraphQL services.
See the example project.
Implementation Details
The plugins introduces a parallel build scope named
sangria-schemagen
and uses it for generating a program for executing the schema introspection code defined insangriaSchemagenSnippet
. The build scope depends on the normalcompile
scope so schema classes are available when running the program. Generate code can be found intarget/scala-2.x/src_managed/sangria-schemagen
and compile artifacts can be found intarget/scala-2.x/sangria-schemagen-classes
.Configuration
Keys are defined in SangriaSchemagenPlugin.autoImport.
sangriaSchemagenSnippet
: Code snippet to access the Sangria Schema.sangriaSchemagenSchema
: GraphQL schema output file. Defaults to file located insideresourceManaged
.sangriaSchemagen
: Generate the GraphQL schema file.