Skip to main content
Version: v3.x

Contexts

Introduction

The DDN CLI allows you set values in the project context to be used in place of commonly used flags to avoid having to repeat them with every command.

The project context config is stored in the .hasura/context.yaml file in the project directory.

For example,

The following is how the command to create a supergraph build on Hasura DDN would typically look:

ddn supergraph build create --supergraph supergraph.yaml --project pet-lion-2649 --env-file .env.cloud`

With the appropriate values set in the context, the command can be shortened to:

ddn supergraph build create
CLI flag vs context hierarchy

A value passed via the CLI command flag takes precedence over the value set in context.

Supported keys

The following are the keys supported to be set in the context along with the flags they correspond to:

Context KeyDefinitionCLI flag(s)
projectThe DDN project to use for the operation--project
supergraphThe supergraph config file to use for the operation--supergraph, --target-supergraph
subgraphThe subgraph config file to use for the operation--subgraph, --target-subgraph
localEnvFileThe env file to use for local operations. e.g. ddn supergraph build local--env-file, --target-env-file
cloudEnvFileThe env file to use for cloud operations. e.g. ddn supergraph build create--env-file, --target-env-file

Initial state

On project directory creation, a context called default is initialized with the following values set by default:

default:
supergraph: <project-root>/supergraph.yaml
subgraph: <project-root>/app/subgraph.yaml
localEnvFile: <project-root>/.env

Manage values in the context

Set a value in the context

To set a value to the context, run:

ddn context set <key> <value>

Get a value from the context

To get a value from the context, run:

ddn context get <key>

Remove a value from the context

To remove a value from the context, run:

ddn context unset <key>

Get all values set in the context

To get the name and contents of the current context, run:

ddn context get-current-context

Multiple contexts

You can create multiple contexts with different values to easily switch between different deployment scenarios.

For example,

Say we have contexts staging and production with the following values:

staging:
project: stg-project
cloudEnvFile: .env.stg
...
production:
project: prod-project
cloudEnvFile: .env.prd
...

Now we can create supergraph builds for the staging and production environments using:

# will use project name and env file from "staging" context
ddn supergraph build create --context staging
# will use project name and env file from "production" context
ddn supergraph build create --context production

Create a new context

To create a new context, run:

ddn context create-context <context-name>

Switch to another context

To switch the current context, run:

ddn context set-current-context <context-name>

Override current context

You can also override the context used for a particular command using the --context flag.

For example:

ddn supergraph build create --context <context-name>
Loading...