Docs
Launch GraphOS Studio

Creating a new subgraph

For your supergraph


This article helps you get started building a new that you can then add to your .

  • If you're building a new API from scratch, we recommend starting from a template!
  • If you already have a API to use as a , see Starting with an existing API.

Starting from a template

The fastest way to create a new is to start with one of the templates provided by the Rover CLI. The rover template command generates the skeleton of a new for you, so you can immediately begin defining your schema and implementing your .

💡 TIP

If your installed version of doesn't include the template command (or if you don't have installed at all), install the latest version.

You start by running rover template use, providing it the ID of your chosen template. For example, the following command creates a new directory called my-subgraph that contains the boilerplate code for a written in TypeScript using the library:

rover template use "my-subgraph" --template="subgraph-typescript-apollo-server"

💡 TIP

To see the full list of available templates, see the Rover template docs

After generating the boilerplate code, you can start filling in your business logic. The generated code includes example for Query and Mutation, along with some entity types to use as your starting point. All templates also come with example GitHub Actions workflows to help with publishing your schema in CI/CD.

When you're ready to add your new to your , see below.

Starting with an existing API

If you have an existing API that you want to use as a , confirm whether it uses a subgraph-compatible library.

  • If it does, consult the library's documentation to determine how to enable its support for .
  • If it doesn't, open an issue to let us know and we'll work with the library's maintainers to add support.

Adding to your supergraph

When you're ready to add a new to your existing , do the following:

  1. Enable federation support in your library.
    • If you built from a template, federation support is already enabled. Otherwise, consult the documentation for your chosen library.
  2. Check your schema against your existing and handle any conflicts.
  3. Set up your CI/CD pipeline to perform checks and also publish your subgraph schema.

After you publish your 's schema for the first time, recognizes it as part of your , and you can start for data from all your subgraphs!

⚠️ CAUTION

Make sure you secure your subgraph so that only can it.

Previous
Next steps
Next
Local subgraph development
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company