Download tutorial as e-book ⚡️
    Loading...

    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: SupergraphManifest
    version: v1
    definition:
    name: base
    envfile: base.env.yaml
    subgraphs:
    - 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:
    CHINOOK_CONNECTOR_CONNECTION_URI: "postgresql://read_only_user:[email protected]:5432/Chinook"

    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
    Did you find this page helpful?
    Start with GraphQL on Hasura for Free
    • ArrowBuild apps and APIs 10x faster
    • ArrowBuilt-in authorization and caching
    • Arrow8x more performant than hand-rolled APIs
    Promo
    footer illustration
    Brand logo
    © 2024 Hasura Inc. All rights reserved
    Github
    Titter
    Discord
    Facebook
    Instagram
    Youtube
    Linkedin