Environment Variables

Environment variables are are key/value pairs that are set outside your source code. The variable value can change depending on the deployment environment.

All values are encrypted and stored as strings.

You can create an environment variable with the same name in Production or Preview environments.

  • Production
    Environment variables set with the Production context are only available in the production environment.
  • Preview
    Environment variables set with the Preview context are only available in preview environments.
  1. Navigate to the dashboard for your project,
  2. Select the Settings tab,
  3. Select the Environment Variables tab,
  4. Enter a name and a value.

Grafbase CLI does not detect any environament variable set through the Dashboard. However, you can specify an environment variable for local development within the file grafbase/.env:

Create the file .env in the grafbase folder/directory and add a key/value pair like the following:

export NAME=VALUE

You can also set a temporary environament variable using the same syntax as within the .env file from the command line before you invoke the grafbase dev command. Learn more about the CLI.

You can access environment variables inside grafbase/schema.graphql using double curly brackets. You must prefix environment variable names with env., as shown in the following example, which sets your authentication provider issuer using the environment variable CLERK_ISSUER_URL:

schema
  @auth(
    providers: [{ type: oidc, issuer: "{{ env.CLERK_ISSUER_URL }}" }]
    rules: [{ allow: private }]
  ) {
  query: Query
}
  • Environment variables are case-insensitive
  • Environment variables cannot start with GRAFBASE_
  • Environment variable names can be up to 255 characters
  • Environment variable values can be up to 5000 characters
  • Environment variable values are always treated as strings