TODO: Provide a bit more guidance on what they're supposed to do and what they
Exercise: Develop with the Apollo Router
🎯 Goal: Get to know how to develop with the Apollo Router to integrate with your platform APIs
For this exercise, we're going to see how we can develop with the Apollo Router and begin to configure it for our platform APIs.
Prerequisites
You will need to download the Apollo Router and rover
CLI.
Connecting the Apollo Router to GraphOS locally
The Apollo Router is a binary that we can run locally and connect to the graph in GraphOS. Let's first get familiar with running the router binary locally with GraphOS. After downloading the router, simply running ./router --help
prints out the help. If the APOLLO_KEY
and APOLLO_GRAPH_REF
environment variables are set, the router will automatically configure with GraphOS for things like usage reporting and managed federation.
The router also has a development mode that enables
Using rover
for easy-mode
Sometimes you need to test out a new thing with your existing graph and the rover
cli makes that easy. It automatically configures the router in development mode and let's you configure whatever you need.
rover
Configuring the Apollo Router
One of the most common configurations for the router is safelisting - docs - and it's something we recommend incorporating into your security strategy. The concept requires that consumers of your APIs pre-register the operations they want to run in production.
You'll need to create a router.yaml
file in the same directory as the router binary and add the configuration for safelisting Hint, you can check the previous docs link for the configuration or see an example configuration:
persisted_queries:enabled: truelog_unknown: truesafelist:enabled: truerequire_id: falseapq:enabled: false # APQ must be turned off
Solutions
Make sure to keep your router running at the end of the exercise! We'll use it for a quick demonstration.
Share your questions and comments about this lesson
Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.
You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.