7. Progressive Override
10m

Overview

In this module we will cover how to progressively migrate from one to another.

By utilizing @override and the label parameter, we can gradually migrate to a different . This allow services to accommodate for the new traffic, and avoid potentially degrading your graph.

Progressive override

in focus: @override

The @override has two parameters:

  • from (required) - indicates the that no longer resolves that

  • label (optional) - a string of arbitrary s

    • percent(<percent-value>) - supports a percent() label to specify the remaining percentage to be resolved from the other

The current state

In this module, we are going to incrementally migrate two from the orders into the customers : User.email and User.phone.

First, let's see what the current state of things are.

  1. In the Explorer, paste the following to get the order information.

    Original field source subgraph
    query GetOrderInfo($orderId: ID!) {
    order(id: $orderId) {
    id
    buyer {
    email
    phone
    }
    }
    }
  2. In the Variables panel, copy and paste the following JSON payload:

    { "orderId": "1" }
  3. Execute the by clicking the Play button in the top-right of the Operations panel.

    https://studio.apollographql.com

    Results showing fields from orders subgraphs

    For demonstration purposes, you will see the (orders subgraph) indicated in the responses.

Using the @override directive

Let's use the @override to gradually roll over 50% of the email and phone to the customers .

  1. Open the customers-schema.graphql file located in the root folder of the repository.

    GitHub view with customers-schema.graphql file highlighted

  2. Add the @override within your imports in the @link at the top.

    ./customers-schema.graphql
    extend schema
    @link(url: "https://specs.apollo.dev/federation/v2.8", import:
    [
    "@key",
    "@requires",
    "@external",
    "@tag",
    "@override"
    ]
    )
  3. Remove @shareable and append the @override to the User's phone and email .

    We'll specify that it's coming from the orders and designating the label to be 50% of traffic: "percent(50)".

    ./customers-schema.graphql
    phone: String
    @tag(name: "private")
    @override(from: "orders", label: "percent(50)")
    email: String!
    @tag(name: "private")
    @override(from: "orders", label: "percent(50)")
  4. Commit your schema changes and wait for your changes to publish.

Testing our changes

Let's make a few requests for the orders information.

  1. In the Explorer, let's run the again to get the order information.

    Original field source subgraph
    query GetOrderInfo($orderId: ID!) {
    order(id: $orderId) {
    id
    buyer {
    email
    phone
    }
    }
    }
  2. In the Variables panel, copy and paste the following JSON payload:

    { "orderId": "1" }
  3. Run the a few times and notice the data returned.

    You should see some responses from the customers , and some from the orders .

    https://studio.apollographql.com

    Results showing fields from customers subgraphs

In production, when you can safely rollover, you will eventually want to remove the label parameter and remove the references from the original .

Task!

Up next

In this module, we've covered how progressive override allows us incrementally migrate . In the next section, we will learn how to enable real-time reviews to our e-commerce .

Previous