GraphQL Federation with Java

Vinay Bedre
2 min readApr 17, 2020

--

Photo of Chandrayaan 2 on ISRO

Apollo Federation provides out of the box support for NodeJS via JavaScript/Typescript. You can read more about this here

In order to use GraphQL Federation in Java, Apollo provides federation-jvm. It also has third-party support for various other languages. You can find the overview below and read more about it here

Third-Party Apollo GraphQL Federation Implementation

It took me sometime to get started with Apollo GraphQL Federation with Java and I created a working example project with federation-jvm to help others like me save time.

You can find repo at

I am using Spring Boot and GraphQL Starter for Spring Boot as its one of most commonly used framework with Java.

There are 4 sub-projects

  1. user
  2. product
  3. review
  4. inventory

and apollo-federation-js project which is a gateway project written in NodeJS. It connects all the sub-projects and expose a single federated graphql end point.

How to run the project?

If you import the project in IntelliJ, you can run all the Spring Boot servers separately under services tab

Spring Boot Projects started in IntelliJ under Services tab

and federation gateway with

node apollo-federation-js/gateway.js

You can also run spring boot projects in each project folders with

./gradlew bootRun

All java project runs on separate ports from 5001 to 5004 and gateway on port 4000.

Once all the servers are running, open localhost:4000 to run graphql playground

Federated GraphQL Playground running on localhost:4000

If you have found this post useful, appreciate via 👏 (once, twice and more).

If you have found different way to implement federation in Java, let me know via comments.

--

--