Apollo Federation in Go part2

Introducing Managed federation

Example Repository

Here’s the final codebase on GitHub. main branch is a version of part-1. part-2 branch is used in this post.

Contents

Managed Federation

Apollo Federation is an essential architecture that allows your organization to scale GraphQL API with multiple implementing services in one graph.

  • deploy automatically
  • observe the changes in each graph

Set up a managed federation

Let’s try out the managed federation feature in our app.

Create the Apollo Studio account

To get started with the managed federation, we need to create the Apollo account.

Create the graph

After the signup flow, create your first graph.

Register schema

Now that we’ve had our graph on Apollo Studio. Next, we will register all of our implementing services’ schema.

go run service-users/main.go
npx apollo service:push \
--graph={your graph here} \
--key=service:{your key here} \
--variant=current \
--serviceName=users \
--serviceURL=http://localhost:4001/query \
--endpoint=http://localhost:4001/query
go run service-profile/main.go
npx apollo service:push \
--graph={your graph here} \
--key=service:{your key here} \
--variant=current \
--serviceName=profile \
--serviceURL=http://localhost:4002/query \
--endpoint=http://localhost:4002/query

Connect gateway to Apollo Studio

Now that our gateway can fetch the latest schema instead of the local one. With managed federation, the service list in the gateway is no longer needed because the gateway can regularly poll the information from the apollo registry.

const gateway = new ApolloGateway();
APOLLO_KEY=xxxxx
yarn add -D dotenv
APOLLO_KEY=xxxxx
"scripts": {
"start": "node -r dotenv/config index.js"
},
yarn start

Conclusion

We’ve walked through Apollo Federation features and Managed federation in these two posts.

Web Developer, TypeScript, React, React Native, Vue.js, Go, Swift, and Ruby on Rails https://manatoworks.me/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store