How to Create a Subgraph
Introduction
You can easily create subgraphs using the CLI and — for cloud projects — the Hasura DDN console. By default, the CLI
will generate an app
subgraph when a new project is initialized.
In your local metadata
ddn subgraph init <subgraph-name>
You can verify this by identifying the new subdirectory in your project with the subgraph's name.
ddn subgraph add <subgraph-name> --subgraph ./<subgraph-name>/subgraph.yaml --target-supergraph ./supergraph.yaml
kind: Supergraph
version: v2
definition:
subgraphs:
- globals/subgraph.yaml
- app/subgraph.yaml
- <subgraph-name>/subgraph.yaml
On a cloud project
By default, when a cloud project is initialized, any subgraphs present in your supergraph configuration will be initialized as well. However, to explicitly add a new subgraph to a cloud project — such as when iterating on an existing project — follow these steps:
Using the CLI
ddn project subgraph create <subgraph-name>
Using the console
Under Settings
> Subgraphs
click + Create New Subgraph
.
Be careful of mismatching subgraphs between your local metadata and a cloud project: if you create a subgraph locally and add it to your supergraph configuration without also creating the subgraph on your cloud project, cloud builds will fail.
To resolve this, ensure that when you create a local subgraph in your metadata, you also create the companion subgraph on the cloud project.