Configuring what environment variables and PHP constants can be queried

With the PHP Constants and Environment Variables via Schema extension, the GraphQL schema is provided with global field _env, which allows to obtain a value from an environment variable, or from a PHP constant.

We must configure the list of allowed environment variables and constants that can be queried.

Each entry can either be:

  • A regex (regular expression), if it's surrounded by / or #, or
  • The full variable or constant name, otherwise

For instance, any of these entries match environment variable "GITHUB_ACCESS_TOKEN":

  • #^([A-Z]*)_ACCESS_TOKEN$#
  • /GITHUB_(\S+)/

There are 2 places where this configuration can take place, in order of priority:

  1. Custom: In the corresponding Schema Configuration
  2. General: In the Settings page

In the Schema Configuration applied to the endpoint, select option "Use custom configuration" and then input the desired entries:

Defining the entries on the Schema Configuration
Defining the entries on the Schema Configuration

Otherwise, the entries defined in the "Environment Fields" tab from the Settings will be used:

Defining the entries on the Settings
Defining the entries on the Settings

There are 2 behaviors, "Allow access" and "Deny access":

  • Allow access: only the configured entries can be accessed, and no other can
  • Deny access: the configured entries cannot be accessed, all other entries can

Defining the access behavior
Defining the access behavior