Odyssey

Federation with .NET (C#) & Hot Chocolate
beta

Intro to federationManaged federation with GraphOSA Hot Chocolate subgraphPublishing to the registryRouter configuration & insightsAdding a subgraphLocal development with rover devEntities and the query planContributing fields to an entityUsing the @requires and @external directivesSchema checksPublishing schema changes
5. Router configuration & insights
3m

Overview

So far, we've got the soundtracks subgraph running and its schema published, but we still need one piece to tie everything together: the router.

In this lesson, we will:

  • Set up the GraphOS Router locally
  • Connect our router to GraphOS
  • Send our first query to our supergraph
  • Explore supergraph insights through the operation and field metrics provided by GraphOS

Downloading the router

The GraphOS Router is a high-performance graph router, available as an executable binary that you can add to your project in a few steps:

Open a terminal window and navigate to the Router directory. So far, we only have the .env file in here with our environment variables and a router-config.yaml file, which we'll get to later.

📦 Router
┣ 📄 router-config.yaml
â”— đź“„ .env

We'll download the router by running the install command in the terminal.

Router
curl -sSL https://router.apollo.dev/download/nix/v1.37.0 | sh

Note: Visit the official documentation to explore alternate methods of downloading the Router.

Now when we check the contents of our Router directory, we'll see that we have a new binary file called router!

📦 Router
┣ 📄 router-config.yaml
┣ 📄 .env
â”— đź“„ router

Router configuration

Let's take a peek inside the router-config.yaml file. This file enables us to customize our router's behavior.

router-config.yaml
supergraph:
listen: 127.0.0.1:5000
include_subgraph_errors:
all: true
telemetry:
instrumentation:
spans:
mode: spec_compliant

For now, we've set two options: the port that the router should run on (under the supergraph.listen property) and to include all the subgraph errors that bubble up. By default, the router redacts the details of subgraph errors in its responses, and we might see an error message like "Subgraph errors redacted". In production environments, this property is usually set to false, but it'll be helpful if you run into any issues following along in this tutorial.

Lastly, we have some telemetry configuration which reduces the kinds of errors we'll see in our terminal output.

Note: To learn more about other options available for configuring the GraphOS Router, check out the documentation.

Running the router

Back in the same terminal window, run the command below that suits your development environment. You'll need to replace the <APOLLO_KEY> and <APOLLO_GRAPH_REF> placeholder values with your supergraph's corresponding values from the Router/.env file we set up in the previous lesson. This command starts up the router locally, tells the router which supergraph to connect to and makes use of the configuration file.

MacOS / Linux / WSL
APOLLO_KEY=<APOLLO_KEY> APOLLO_GRAPH_REF=<APOLLO_GRAPH_REF> ./router --config router-config.yaml
Windows powershell
$env:APOLLO_KEY="<APOLLO_KEY>"
$env:APOLLO_GRAPH_REF="<APOLLO_GRAPH_REF>"
./router --config router-config.yaml

We'll see a few lines of router output, and finally a message that our router is running on port 5000, ready to receive queries!

Let's copy this address, we'll need it to set our connection settings in Studio.

http://127.0.0.1:5000

This tells outside consumers of our API what endpoint they can use to query our schema.

Note: Because our router is currently running at http://127.0.0.1:5000, it's not actually accessible to the outside world. But we can still add query the router from our own machines.

Connecting the router to GraphOS

Let's flip back over to Studio.

Click on the README tab in the sidebar.

Next, tap the Connection Settings link at the top of the page.

https://studio.apollographql.com

Studio - README

We'll paste the router address we copied (http://127.0.0.1:5000) as the endpoint, then save.

https://studio.apollographql.com

Studio - Connection Settings

Let's get to querying our supergraph!

Testing our schema

Select the Explorer tab from the sidebar.

Let's put together a query that retrieves the titles and descriptions of our featured playlists.

query GetFeaturedPlaylists {
featuredPlaylists {
id
name
description
}
}

Now let's run this query.

https://studio.apollographql.com

Explorer - query featured playlists

Fantastic, we get back our list of featured playlists.

GraphOS provides us with observability tools to monitor the health and performance of our supergraph. These tools help surface patterns in how our supergraph gets used, which helps us continue to improve it. We're still in tutorial-land, so there isn't any real production traffic going to our supergraph, but we can still check out our supergraph insights!

Run the operations below a few more times to see some data pop up before we check out the metrics.

GetPlaylistDetails operation
query GetPlaylistDetails {
playlist(id: "6Fl8d6KF0O4V5kFdbzalfW") {
id
name
description
tracks {
id
name
durationMs
explicit
uri
}
}
}
AddItemsToPlaylist operation
mutation AddItemsToPlaylist {
addItemsToPlaylist(
input: { playlistId: "DoesNotExist", uris: ["ASongAboutGraphQL"] }
) {
code
message
success
playlist {
id
name
tracks {
id
name
}
}
}
}

Operation metrics

Let's navigate over to the Insights page.

https://studio.apollographql.com

Insights page in Studio, showing Operations tab

The Operations tab gives us an overview of operation request rates, service time, and error percentages, including specific operations for each of these that might be worth drilling deeper into.

We recommend that clients clearly name each GraphQL operation they send to the supergraph, so we can easily view them in our metrics.

We can also filter to select a particular operation to see more specific details about its usage, as well as its signature, which is the shape of the query. We can see the number of requests that have been made and how long each request takes over time.

https://studio.apollographql.com

Operations page filter for a specific operation in Studio

Field metrics

Next, let's check out field metrics. Head over to the Fields tab.

Beside each field, we'll see the total number of requesting operations, which is the number of operations in a given period that have included that particular field.

https://studio.apollographql.com

Fields page in Studio

We can use both operation and field metrics to monitor the health and usage of our supergraph's types and fields and determine where we can start to improve, based on how they're performing and how our clients are using them.

Practice

Which of the following operation metrics does GraphOS provide?

Key takeaways

  • Operation metrics provide an overview of operation request rates, service time, and error percentages within a given time period or for a specific operation.
  • Field metrics include the requesting operations metric, which lists the number of operations in a given period that have included the particular field.

Up next

We're going to introduce a whole new domain in the form of a new subgraph: it's an activity we're all familiar with, and it's much more fun when we've got music to set the mood. It's a subgraph all about recipes!

Previous
Next

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.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              GraphOS Router

              A scalable runtime for supergraphs that's fully integrated with GraphOS and based on the Apollo Router Core. Can be cloud- or self-hosted.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              GraphOS Router

              A scalable runtime for supergraphs that's fully integrated with GraphOS and based on the Apollo Router Core. Can be cloud- or self-hosted.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              Router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              GraphOS Router

              A scalable runtime for supergraphs that's fully integrated with GraphOS and based on the Apollo Router Core. Can be cloud- or self-hosted.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              querying

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              operations

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              GraphQL

              An open-source query language and specification for APIs that enables clients to request specific data, promoting efficiency and flexibility in data retrieval.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              operations

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              Operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              Field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              operations

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              NEW COURSE ALERT

              Introducing Apollo Connectors

              Connectors are the new and easy way to get started with GraphQL, using existing REST APIs.

              Say goodbye to GraphQL servers and resolvers—now, everything happens in the schema!

              Take the course