MIT License Download CircleCI

Apollo Federation on the JVM

Packages published to our bintray repository and available in jcenter; release notes in

An example of graphql-spring-boot microservice is available in spring-example.

Getting started

Dependency management with Gradle

Make sure JCenter is among your repositories:

repositories {

Add a dependency to graphql-java-support:

dependencies {
    implementation 'com.apollographql.federation:federation-graphql-java-support:0.4.1'

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:

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 minimal but complete example is available in InventorySchemaProvider.

Federated tracing

To make your server generate performance traces and return them along with responses to the Apollo Gateway (which then can send them to Apollo Graph Manager), install the FederatedTracingInstrumentation into your GraphQL object:

GraphQL graphql = GraphQL.newGraphQL(graphQLSchema)
  .instrumentation(new FederatedTracingInstrumentation())

It is generally desired to only create traces for requests that actually come from Apollo Gateway, as they aren't helpful if you're connecting directly to your backend service for testing. In order for FederatedTracingInstrumentation to know if the request is coming from Gateway, you need to give it access to the HTTP request's headers, by making the context part of your ExecutionInput implement the HTTPRequestHeaders interface. For example:

    HTTPRequestHeaders context = new HTTPRequestHeaders() {
        public @Nullable String getHTTPRequestHeader(String caseInsensitiveHeaderName) {
            return myIncomingHTTPRequest.getHeader(caseInsensitiveHeaderName);