Create subgraph
Stop dev mode
Before we add the subgraph, we'll first need to stop dev
mode in the CLI. In the terminal tab in which this is
running, press CTRL+C
.
Add the new subgraph
Using the same tab, while we're still in the project directory, we'll add a second subgraph using the following command:
ddn create subgraph chinook
The CLI should respond that the subgraph was successfully created and that you need to add this new subgraph to a
SupergraphManifest to start using it in your DDN project. We can make our base.supergraph.hml
look like this:
kind: SupergraphManifestversion: v1definition:name: baseenvfile: base.env.yamlsubgraphs:- app- chinook
Connect a new data source
Since this is a PostgreSQL database, we can add a connector manifest using the following CLI command:
ddn add connector-manifest chinook_connector --subgraph chinook --hub-connector hasura/postgres --type cloud
Modify the base.env.yaml
file in the root of your project by adding the CHINOOK_CONNECTOR_CONNECTION_URI
environment
variable with the connection string under the chinook
subgraph:
supergraph: {}subgraphs:app:APP_CONNECTOR_CONNECTION_URI: "postgresql://read_only_user:[email protected]:5432/v3-docs-sample-app"app:
Then, in our chinook/chinook_connector/connector/chinook_connector.build.hml
, we can add the new subgraph and
connection string:
CONNECTION_URI:valueFromEnv: CHINOOK_CONNECTOR_CONNECTION_URI
We can then run dev mode to generate a new build, introspect our Chinook data source, and watch for changes:
ddn dev
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs