Integrating Dgraph in Modus is a powerful solution to expose AI services with “memory” or to create, maintain and leverage knowledge graphs.

After you have initialized a Modus app:

  1. Provision your environment
    Run Dgraph locally or provision a Graph on Hypermode.

  2. Declare the connection in the App Manifest
    Edit the App Manifest to declare a connection to the Dgraph instance using the Dgraph connection string.

    For local instance of Dgraph, the connection string is dgraph://localhost:9080.
    For a Graph on Hypermode, the connection string is available from the Hypermode dashboard.

    Make sure to use a variable for the bearer token so you don’t commit secrets in your project!

modus.json
"connections": {
    // This defines a dgraph connection
    // Get the connection string from the Hypermode dashboard.
    // use a variable for bearer token
    "my-dgraph": {
      "type": "dgraph",
      "connString": "dgraph://modus-recipes-backend-hypermode.hypermode.host:443?sslmode=verify-ca&bearertoken={{API_KEY}}"
    }
  }


Note: you can also define a Dgraph connection Using the gRPC target parameter.

  1. Set the secrets
    When working locally set your Environment Secrets using a .env file.

    .env.dev.local
    MODUS_MY_DGRAPH_API_KEY='<your API Key>'
    


    When your app is deployed on Hypermode, add the connection secrets in the Hypermode Console.

  2. Use Modus SDK to query and mutate the graph.
    In your Modus app, use the Modus SDK to fetch data from Dgraph.

Resources

  • Manage Schema to deploy a schema to your Dgraph instance if needed.
  • Get inspirations from Modus Recipes where you’ll find examples using Dgraph in Modus.
  • Check the Modus SDK examples for Go or AssemblyScript