1. Course overview and setup
3m

👋 Welcome to Performance in the router

In this course, we'll troubleshoot some preexisting performance issues in a API using the .

We'll begin with a simulated production environment, with several and a running . Right away, we'll see that our graph is receiving too much traffic, and performance is suffering. As we explore different ways to improve latency, we'll use observability tools that let us monitor our changes as we make them.

Prerequisites

Install Docker and Docker Compose

To run the containers for this course, you'll need to have both Docker and Docker Compose installed on your computer. After installing, make sure that Docker is running.

Note: Please ensure that using Docker complies with your organization's guidelines and licensing permissions. If using Docker is not possible, Podman and Colima are alternatives you can consider.

Task!

Clone the repository

In the directory of your choice with your preferred terminal, clone the app's starter repository:

git clone https://github.com/apollographql-education/odyssey-router-performance.git
Task!

Sign up for an Apollo GraphOS account

Don't have an account yet? Create one now and you're all set with the Free plan! Jump to the next step.

If you already have an existing account within an organization with an , you must have the role of Graph Admin to be able to create . You can still follow along if your organization is on a different plan, but you won't be able to complete certain hands-on tasks. We recommend signing up with your personal email for a Free plan.

Task!

Create your graph

Even though we'll run everything in our "production" setup locally, we still need to create a in . This will give us the credentials we need to connect our to Enterprise features.

  1. Open a new browser window and go to GraphOS Studio.

  2. If you have a brand new organization, you can create a new by clicking on Connect a GraphQL API.

    studio.apollographql.com

    Add new graph - empty state

    Otherwise, we can create a new by clicking the Add new graph button, then Connect a GraphQL API.

    studio.apollographql.com

    Add new graph - existing graphs

  3. We'll give our a descriptive title, keep the default settings for Graph architecture as "", then click Next.

    studio.apollographql.com

    The create graph modal in Studio

  4. We should now see a modal with options for publishing a schema.

    studio.apollographql.com

    A modal window showing options for publishing the schema for our graph

We're ready to store these !

Task!

Storing variables

The Docker process we'll boot up in the next lesson includes a locally-running . In order for this router to connect with our newly-created , we need to provide it with a couple of .

  • APOLLO_KEY: Your 's API key, used to interact with a single in . It starts with something like "service:your-graph-name". Note that this is different from your personal API key, which we used to authenticate , and which grants you partial access to every in the organization you belong to.
  • APOLLO_GRAPH_REF: The erence (or graph ref) for our , which we'll use to tell where to publish our . A graph ref starts with the graph's ID, followed by an @ symbol, followed by the .

In an IDE of your choice, open up the docker-compose.yaml file located in the root of the project directory. Scroll down until you find the router key under services.

docker-compose.yaml
router:
image: ghcr.io/apollographql/router:v1.55.0
environment:
- APOLLO_KEY=add-your-apollo-key-here
- APOLLO_GRAPH_REF=add-your-graph-ref-here

Right now we have placeholder (and non-functional) values stored for our APOLLO_KEY and APOLLO_GRAPH_REF environment variables. We're going to swap these placeholder values out for our own .

Let's see where we access those values.

APOLLO_KEY and APOLLO_GRAPH_REF

  1. Go back to the configuration options in Studio that appeared after you created your . Make sure you're on the Schema Document tab.

  2. First, make sure that the Supergraph Pipeline Track dropdown is set to Federation 2.8 Supergraph.

  3. Below, take a little peek at the command for publishing a . We won't need to run this command in this course (our is part of our container setup), so for now, we just need the APOLLO_KEY environment variable here. This will allow our locally-running to connect with our Enterprise .

    APOLLO_KEY=your-graphs-apollo-key \
    rover subgraph publish your-graph-name@current \
    --name products --schema ./products-schema.graphql \
    --routing-url http://products.prod.svc.cluster.local:4001/graphql
  4. Click on the eye icon on the code block to reveal the full value of APOLLO_KEY. Copy the value for APOLLO_KEY where indicated into the docker-compose.yaml file. We'll need it for the next step, and won't have access to the same key again through Studio.

    studio.apollographql.com

    The Apollo Key value outlined, along with the eye icon that toggles the value from hidden to visible

    docker-compose.yaml
    router:
    image: ghcr.io/apollographql/router:v1.55.0
    environment:
    - APOLLO_KEY=add-your-apollo-key-here
    - APOLLO_GRAPH_REF=add-your-graph-ref-here
  5. Now let's go back to Studio to get our . The value we're looking for appears in the same code block, directly after the " publish" part of the command (something like your-graph-name@current). We'll save this value as an environment variable as well, but we can access it anytime from our 's home page.

    studio.apollographql.com

    The graph ref value outlined

    APOLLO_KEY=your-graphs-apollo-key \
    rover subgraph publish your-graph-name@current \
    --name products --schema ./products-schema.graphql \
    --routing-url http://products.prod.svc.cluster.local:4001/graphql

Great! Your docker-compose.yaml file should have a router section that looks something like this.

router:
image: ghcr.io/apollographql/router:v1.55.0
environment:
- APOLLO_KEY=service:my-special-apollo-key
- APOLLO_GRAPH_REF=my-graph@current
Task!

Up next

Let's get our code up and running in the next lesson.


Share your questions and comments about this lesson

This course is currently in

beta
. 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.