Skip to main content

Environmental variables

Wrapper developers can declare a map of environmental variables for application developers to provide.

If you're an application developer, check out ClientConfig. If you're a wrapper developer, keep reading!

Schema declaration#

To use environmental variables, wrapper developers must first declare an Env type and add the @env directive to methods in the Wrapper Schema. You can learn more about the schema declarations in the Environmental Variables section of the Wrapper Schema documentation.

type Env {
str: String!
type Module {
arg: String!
): String! @env(required: true)

Access Env in the module#

Environmental variables can be used in both plugin wrappers and Wasm wrappers.

Env in plugin wrappers#

Plugin wrapper developers can access the Env instance as a class property.

const env: Env = this.env;

Env in wasm wrappers#

Wasm wrapper developers can access the Env instance by accepting the Env as a second argument in their module's methods. When an application developer invokes the method, the environmental variables they set in their ClientConfig will be provided.

// App developers are required to provide Env to invoke this method
export function methodRequireEnv(_: Args_methodRequireEnv, env: Env): Env {
return env;
// Env is optional when invoking this method
export function methodOptionalEnv(_: Args_methodOptionalEnv, env: Env | null): Env | null {
return env ? (env as Env) : null;