Set up your graph

Build a federated GraphQL API with GraphOS


Hello! 👋 This set of guides gets you up and running with a graph that integrates data from products, users, and inventory services. A graph is network of interconnected data that enables clients to traverse relationships and fetch exactly what they need in a single request.

When a graph is made of several underlying services—sometimes called subgraphs—the entire graph is sometimes called a supergraph. Clients make requests to the federated graph's single entry point called the router.

In this and the following guides, you will:

  • Set up a supergraph

  • Learn how to use Apollo's tools like GraphOS Studio, Rover CLI and Apollo Sandbox

Let's start building!

🧰 Meet your tools

Throughout this guide you'll be using the following Apollo tools:

  • GraphOS Studio is the primary web interface for GraphOS. Studio helps you monitor, manage, and collaborate on your GraphQL APIs.

  • The Rover CLI is the primary command-line interface for GraphOS.

None of these tools requires a paid plan.

Create a GraphOS account

note
Skip to the next section if you already have a GraphOS account.

You need an account to work with GraphOS. Sign up for a Free plan at studio.apollographql.com.

Create a graph

  1. If your organization hasn't created any graphs in Studio yet, Studio presents the following screen that encourages you to get started with the Rover CLI. Follow the instructions on the screen to install Rover and authenticate it with your GraphOS account. Then, under Select your starting point, click Connect existing GraphQL API.

    GraphOS Studio when an organization hasn't created any graphs. The screen prompts users to install the Rover CLI, connect it to GraphOS, and select a starting point: either a REST or GraphQL API.

    This guide shows how to use a retail demo graph as the existing GraphQL API.

  2. If you already have existing graphs, you won't see this screen, but it's still helpful to start by installing Rover with the appropriate command for your system:

    terminal
    MacOS / Unix-like
    curl -sSL https://rover.apollo.dev/nix/latest | sh	
    terminal
    Windows
    iwr 'https://rover.apollo.dev/win/latest' | iex	

    Then, click Add new graph on the upper right of the Studio homepage and select Connect existing GraphQL API.

    GraphOS Studio when an organization has one more graphs.
  3. In the modal that appears, enter a Graph title, for example Ecomm Example. Leave the Graph Architecture as Supergraph (Default). Click Next.

  4. A dialog titled Publish your schema using Federation appears. Copy the entire example code block to a local text file using the copy button.

    A dialog from GraphOS Studio displays a hidden API key and graph ref.

    It should look something like this:

    terminal
    APOLLO_KEY=service:Ecomm-Example:••••••••••••••••••••• \
    rover subgraph publish Ecomm-Example@current \
    --schema ./products-schema.graphql \
    --name your-subgraph-name \
    --routing-url http://products.prod.svc.cluster.local:4001/graphql
    • The protected value that appears after APOLLO_KEY= and begins with service: is your graph API key.

    • The value that appears after rover subgraph publish is your graph ref. By default, it ends with @current.

    • The --schema option specifies the path to the schema file to publish.

    • The --name option specifies the name of the subgraph.

    • The --routing-url is the address the router should send subrequests for this particular subgraph to.

    caution
    API keys are secret credentials. Never share them outside your organization or commit them to version control. Delete and replace API keys that you believe are compromised.
  5. Leave the dialog open. This guide now shifts to the demo graph and local development. You'll complete setup with Rover and return to Studio for the final steps in this guide.

Set up retail demo graph

Apollo's retail demo graph is a demonstration supergraph for a retail business containing services for checkout, discovery, inventory, orders, products, reviews, shipping, and users. It includes prebuilt schema and server code. Download or clone it from its GitHub repository.

To ensure you can run it locally in the next step, install the latest LTS version of Node.js.

note
While the retail demo uses Node.js for all its services, Apollo Federation is compatible with many GraphQL server libraries. You can also federate services that use different programming languages and different server libraries.

Next steps

Here's where the fun begins. Jump over to the next guide to start developing your graph.

Feedback

Forums