Environment variables

App-level variables and the team-owned shared variables that link into several apps at once.

A variable is plain or secret and applies to one or more targets (production, preview). A shared variable is owned by the team and linked into apps; the link is what injects it.

A secret variable is write-only and immutable

Once a row is secret, upsertEnv, renameEnv and saveSharedVar refuse it, setAppEnv skips it, and importEnv counts it in skippedSecrets instead of writing over it. Rotating one is delete + create, and no mutation turns a secret back into a plain variable. The reverse (plain to secret) is always allowed.

App variables

env

Any signed-in principal. Returns [EnvVar!].

Env vars of a single project (requires manage_env).

ArgumentTypeDescription
appIdString!
query {
  env(appId: "prj_9f1c2ab7d3e4f5a6") {
    id
    key
    type
    targets
    isMasked
  }
}

allAppEnv

Any signed-in principal. Returns [AppEnvGroup!].

Every app's env vars in the active team, grouped by project.

query {
  allAppEnv {
    app {
      slug
    }
    vars {
      key
      type
    }
  }
}

upsertEnv

Needs manage_env. Returns EnvVar.

Create or update an env var, then return the stored entity.

ArgumentTypeDescription
inputUpsertEnvInput!
input.appIdString!
input.keyString!
input.targets[EnvTarget!]One of preview, production.
input.typeEnvVarType!One of plain, secret.
input.valueString!
mutation {
  upsertEnv(
    input: { appId: "prj_9f1c2ab7d3e4f5a6", key: "DATABASE_URL", value: "postgres://shop:secret@db-orders:5432/orders", type: secret, targets: [production, preview] }
  ) {
    id
    key
    type
    targets
    isMasked
  }
}

renameEnv

Needs manage_env. Returns EnvVar.

Rename an env var's key in place, then return the stored entity.

ArgumentTypeDescription
idString!
newKeyString!
mutation {
  renameEnv(id: "env_9f1c2ab7d3e4f5a6", newKey: "POSTGRES_URL") {
    id
    key
    type
    targets
    isMasked
  }
}

deleteEnv

Needs manage_env. Returns Boolean.

Delete an env var. Returns true.

ArgumentTypeDescription
idString!
mutation {
  deleteEnv(id: "env_9f1c2ab7d3e4f5a6")
}

setAppEnv

Needs manage_env. Returns Int.

Replace an app's whole env set from the .env editor (upsert the given entries, delete the rest). New vars default to plain; existing secrets are left untouched. Returns the resulting variable count.

ArgumentTypeDescription
appIdString!
defaultTargets[EnvTarget!]One of preview, production.
entries[EnvEntryInput!]!
entries.keyString!
entries.valueString!
mutation {
  setAppEnv(
    appId: "prj_9f1c2ab7d3e4f5a6"
    entries: [{ key: "NODE_ENV", value: "production" }, { key: "PORT", value: "3000" }]
    defaultTargets: [production, preview]
  )
}

importEnv

Needs manage_env. Returns EnvImportResult.

Bulk-import a .env-style blob. Every line lands as plain, so a key that already exists as a secret is skipped rather than downgraded.

ArgumentTypeDescription
appIdString!
blobString!
targets[EnvTarget!]One of preview, production.
mutation {
  importEnv(appId: "prj_9f1c2ab7d3e4f5a6", blob: "API_URL=https://api.example.com\nLOG_LEVEL=info", targets: [production]) {
    added
    skippedSecrets
  }
}

makeEnvSecret

Needs manage_env. Returns Boolean.

Make a variable Secret without changing its stored value or scope.

ArgumentTypeDescription
idString!
mutation {
  makeEnvSecret(id: "env_9f1c2ab7d3e4f5a6")
}

Shared variables

sharedVars

Needs manage_env. Returns [SharedVar!].

All shared variables in the active team, A->Z.

query {
  sharedVars {
    id
    key
    type
    teamWide
  }
}

sharedVarsForApp

Needs manage_env. Returns [AppSharedVar!].

Every team shared variable as seen from one app, with its opt-in (link) state.

ArgumentTypeDescription
appIdString!
query {
  sharedVarsForApp(appId: "prj_9f1c2ab7d3e4f5a6") {
    id
    key
    linked
    inScope
  }
}

saveSharedVar

Needs manage_env. Returns SharedVar.

Create or update a shared variable; returns the saved entity.

ArgumentTypeDescription
inputSaveSharedVarInput!
input.appIds[String!]The per-app links, as a whole set. OMIT to leave the existing links untouched - that is what preserves setSharedVarAppLink's app-side toggle.
input.environmentIds[ID!]!
input.idString
input.keyString!
input.projectIds[ID!]!
input.targets[EnvTarget!]One of preview, production.
input.teamIds[ID!]!Teams every app of which gets this variable. ONE team => it is only SUGGESTED there and the per-app link injects (ADR-0012); TWO OR MORE => it is injected into every app of every one of them, with no link, at the lowest precedence. The caller must hold manage_env across the whole of every team named here.
input.typeEnvVarType!One of plain, secret.
input.valueString!
mutation {
  saveSharedVar(
    input: { key: "API_BASE_URL", value: "https://api.example.com", type: plain, teamIds: [], projectIds: [], environmentIds: [], appIds: ["prj_9f1c2ab7d3e4f5a6"] }
  ) {
    id
    key
    type
    teamWide
  }
}

Needs manage_env. Returns Boolean.

Link or unlink a shared variable to one app. Returns true.

ArgumentTypeDescription
appIdString!
linkedBoolean!
varIdString!
mutation {
  setSharedVarAppLink(varId: "svar_9f1c2ab7d3e4f5a6", appId: "prj_9f1c2ab7d3e4f5a6", linked: true)
}

deleteSharedVar

Needs manage_env. Returns Boolean.

Delete a shared variable. Returns true.

ArgumentTypeDescription
idString!
mutation {
  deleteSharedVar(id: "svar_9f1c2ab7d3e4f5a6")
}

makeSharedVarSecret

Needs manage_env. Returns Boolean.

Make a variable Secret without changing its stored value or scope.

ArgumentTypeDescription
idString!
mutation {
  makeSharedVarSecret(id: "svar_9f1c2ab7d3e4f5a6")
}

See also

Did this page help you?

On this page