Produces a graphql-java
GraphQLSchema from Guice bindings.
Enable the user to compose a GraphQL schema from fragments produced dynamically at runtime, statically at compile time, or some combination of the two via dependency injection.
Add the following to your dependencies in pom.xml.
<dependency>
<groupId>com.moodysalem.graphbuilder</groupId>
<artifactId>graphbuilder-guice</artifactId>
<version>...</version>
</dependency>There are two important classes for users of this module:
GraphBuilderModuleGraphBinder
The first is the Guice module that must be installed to provide the GraphQL
schema binding. The second allows for binding GraphQLFieldDefinition.Builders
and DataFetcher/DataFetcherFactorys to positions in the final GraphQL
schema.
The GraphQL schema is bound to a scope provided by the user. If you wish to construct the schema only once when injected, use a singleton scoped schema. Use the eager singleton scope to construct the schema at injector creation time.
Schema components provided by modules may be bound to different scopes. This means that some parts of schema can be dynamic, i.e. depend on other Guice keys, and other parts can be singleton scoped. GraphBuilder exposes all the flexibility of Guice in constructing each part of your schema.
There are multiple ways to provide schema definitions to GraphBuilder.
You can write provider methods on your Guice modules using the annotation
@ProvidesIntoSet and return any of FieldDataFetcher,
FieldDataFetcherFactory, FieldDefinition, GraphQLType, GraphQLDirective
or any combination via SchemaBundle.
This must be combined with the Guice MultibindingsScanner.asModule() module
in order for the @ProvidesIntoSet annotations to be processed.
GraphBinder is a helper class that allows you to construct bindings of
positions in the schema to data fetchers, data fetcher factories, and field
definitions. The interface is similar to the Guice MapBinder/Multibinder.
Examples can be found at docs/example.