2. Journey through the supergraph
3m

Overview

What actually happens when we add a new to Poetic Plates?

In this lesson, we will:

  • Trace the journey of a client request through the
  • Describe how the creates to resolve across multiple s

In the beginning...

We started off from humble cooking beginnings: a small called recipes. Clients sent queries to the , which routed the queries to the recipes . Simple! Because we only had one subgraph, that subgraph's schema and the were essentially one and the same.

Now that we want to add another to the mix, what happens?

First, we'll need to publish that to . This will trigger a .

Note: If you've completed GraphOS: Safe API delivery, the next section will feel familiar!

The launch process

A launch represents the complete process of making schema updates to a .

When the schema registry gets a new , or an updated version of an existing subgraph schema, it starts to build the supergraph schema. The schema registry attempts to combine all of the schemas from its registered into a single . This process is also known as composition.

If fails, we'll see an error in Studio, and the process stops there. No stress: we can use the error messages to fix the issue in our , and then try publishing the subgraph again.

If succeeds and there are no validation errors, the schema registry produces a . (In the next section, we'll find out how the uses this supergraph schema.)

The schema registry automatically sends the to an internal service within called Apollo Uplink. Uplink is a server that stores the latest supergraph schema for each graph. The fetches the latest schema from Uplink and uses this new schema to respond to client requests.

With that, the completes successfully!

Exciting stuff! Now, let's revisit the experience of sending to the , this time within the context of having multiple .

The journey of a GraphQL operation through the supergraph

Let's start at the beginning: from the client request.

Step 1: The client request

First, the client sends a to the . The client has no clue which belong to which —or even that there are subgraphs at all!

Client sends a GraphQL operation to the router

Step 2: Building a query plan

The looks at the in the and uses the supergraph schema to figure out which are responsible for resolving each .

Router uses the supergraph schema

It uses this information to build a query plan, a list of smaller to execute on the . The also specifies the order in which the subgraph operations need to run.

Router builds a query plan

Step 3: Executing the query plan

Next, the carries out the by sending the smaller to each of the it needs data from.

Router sends operations to subgraphs

The resolve the the same way as any other : they use their and to retrieve and populate the requested data.

Subgraphs resolve data

Step 4: The subgraph responses

The send back the requested data to the , and then the router combines all those responses into a single JSON object.

Subgraphs return data

Step 5: Sending data back to the client

Finally, the sends the JSON object back to the client.

Subgraphs return data

And that's the end of our 's journey!

The full journey of an operation through the supergraph, in one diagram

Key takeaways

  • The uses the to create a for the incoming . The query plan is a list of smaller operations the router can execute on different to fully resolve the incoming operation.
  • The carries out the by executing the list of on the appropriate .
  • The combines all the responses from the into a single JSON object, which it sends back to the client.

Up next

Let's see this process in action! In the next lesson, we'll add the kitchenware to our .

Previous

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.