Apollo Federation on the JVM
Packages published to our bintray repository and available in jcenter; release notes in RELEASE_NOTES.md.
An example of graphql-spring-boot microservice is available in spring-example.
Getting started
Dependency management
Make sure JCenter is among your repositories:
repositories {
jcenter()
}
Add a dependency to graphql-java-support
:
dependencies {
implementation 'com.apollographql.federation:federation-graphql-java-support:0.2.0'
}
graphql-java schema transformation
graphql-java-support
produces a graphql.schema.GraphQLSchema
by transforming your existing schema in accordance to the
federation specification.
It follows the Builder
pattern.
Start with com.apollographql.federation.graphqljava.Federation.transform(…)
, which can receive either:
- A
GraphQLSchema
; - A
TypeDefinitionRegistry
, optionally with aRuntimeWiring
; - A String, Reader, or File declaring the schema using the Schema Definition Language,
optionally with a
RuntimeWiring
;
and returns a SchemaTransformer
.
If your schema does not contain any types annotated with the @key
directive, nothing else is required.
You can build a transformed GraphQLSchema
with SchemaTransformer#build()
, and confirm it exposes query { _schema { sdl } }
.
Otherwise, all types annotated with @key
will be part of the _Entity
union type,
and reachable through query { _entities(representations: [Any!]!) { … } }
. Before calling SchemaTransformer#build()
,
you will also need to provide:
- A
TypeResolver
for_Entity
usingSchemaTransformer#resolveEntityType(TypeResolver)
; - A
DataFetcher
orDataFetcherFactory
for_entities
usingSchemaTransformer#fetchEntities(DataFetcher|DataFetcherFactory)
.
A minimal but complete example is available in InventorySchemaProvider.