Gateway configuration options
#
Gateway Configuration FileGraphQL Portal Gateway server is configured from gateway.json|yaml
file which should be located in a directory ./config
relative to the command.
For example, if we are launching graphql-portal
command from /opt/graphql-portal
directory, then the gateway configuration
should be located in /opt/graphql-portal/config/gateway.json|yaml
.
#
API Configuration FilesIt is possible to use the gateway with static configuration files, in that case you have to set use_dashboard_configs
to false
.
When done so, the gateway will try to load API Configurations from the directories specified in the following options:
- apis_path
- middleware_path
- sources_path.
Important
In all of the above options, the path is relative to the directory in which we launch the gateway, i.e. if we are launching
the server in /opt/graphql-portal
and the apis_path
is set to config/apis
, then we'll look for the files in
/opt/graphql-portal/config/apis/
directory.
The combination of these options allows us to have a flexible configuration structure with separation of concerns, which if necessary can then be versioned. Here is an example of a typical configuration structure:
{ "use_dashboard_configs": false, "apis_path": "config/apidefs", "middleware_path": "config/middlewares", "sources_path": "config/sources"}
Our directory listing will then look like that:
$ tree config/configโโโ apidefsโย ย โโโ test-api.jsonโโโ datasourcesโย ย โโโ test-data-source.yamlโโโ gateway.jsonโโโ middlewares
#
Environment variablesIt is possible to override certain configuration options by using environment variables. To do that, you'll have to replace
the values of the variables in the configuration file with @@ENV_VARIABLE_NAME
.
For example, lets take the following configuration file:
{ "hostname": "@@HOSTNAME", "listen_port": @@PORT, "pool_size": 1, "secret": "", "apis_path": "config/apidefs", "sources_path": "config/datasources", "middleware_path": "config/middlewares", "redis": { "connection_string": "redis://localhost:6379" }, "use_dashboard_configs": false, "enable_control_api": false, "log_level": "@@LOG_LEVEL"}
As you can see, there are three values which were replaced with @@VARIABLE
. Values which were specified in that way are
going to be taken from the environment variables.
#
hostnameThe hostname to bind the gateway node to.
#
listen_portThe port on which GraphQL Portal Gateway will listen for the incoming connections.
#
servernameOptional string. This value should be set to the external server name when gateway is used behind the load-balancer proxy.
#
pool_sizeOptional number. The size of the NodeJS Cluster pool, i.e. how many instances of the gateway are going to be launched on the same host. It is recommended to keep this number equal to the number of CPU cores on the machine. Setting this value to 1 will launch a single-instance gateway. Setting it to 0 or removing it will use all the available CPU cores on the machine.
#
use_dashboard_configsThis boolean value specifies whether to read the API configurations from the local file or from a GraphQL Portal Dashboard.
If set to false
, the gateway will try to read the configuration files locally and will search for them in the locations
specified in the following configuration options:
- apis_path
- middleware_path
- sources_path.
If set to true
, it will try to connect to dashboard (see below for dashboard configuration) and get the configuration
from there.
#
dashboard_configOptional. This value will be used only when use_dashboard_configs
is set to true
.
It contains a required options connection_string
, which specifies the URL and connection parameters to the Dashboard.
Example:
{ "use_dashboard_configs": true, "dashboard_config": { "connection_string": "http://graphql-portal-dashboard.svc.local:8080" }}
#
apis_pathPath to a directory with API definition files. Read more about API Configuration Files here.
#
middleware_pathPath to a directory with custom middlewares. API Configuration Files here
#
sources_pathPath to a directory with data source files. API Configuration Files here
#
enable_control_apiEnables or disables the Control API which is used to update GraphQL Schema definitions.
#
control_api_configOptional. Used only when enable_control_api
is set to true
. Contains only one property endpoint
which specifies
the URL path on which to which the Control API will be bind.
{ "enable_control_api": true, "control_api_config": { "endpoint": "/control-api" }}
#
corsOptional. Enables and configures CORS requests.
CORS requests from Dashboard are enabled by default when use_dashboard_configs
is set to true.
#
enabledBoolean, false
by default. Enables CORS configuration.
#
originsArray of strings. Configures the Access-Control-Allow-Origin CORS header. Expects an Array of valid origins.
#
methodsArray of strings. Configures the Access-Control-Allow-Methods CORS header. Expects an array of HTTP Methods.
#
allowedHeadersArray of strings. Configures the Access-Control-Allow-Headers CORS header. Expects and Array of headers.
#
exposedHeadersArray of strings. Configures the Access-Control-Expose-Headers CORS header.
#
credentialsArray of strings. Configures the Access-Control-Allow-Credentials CORS header.
#
maxAgeInteger. Configures the Access-Control-Max-Age CORS header.
#
optionsSuccessStatusInteger. Provides a status code to use for successful OPTIONS requests, since some legacy browsers (IE11, various SmartTVs) choke on 204.
#
enable_metrics_recordingBoolean. Enables metrics gathering. Disabled by default.
#
log_formatOptional. Can be text
or json
. Default value is text
.
#
log_levelPossible values are: 'debug' | 'info' | 'warn' | 'error'.
#
datadog_loggingConfigures sending of log messages to Datadog.
#
enabledBoolean. Enable or disable logging to Datadog. Defaults to false.
#
apiKeyString. Datadog API key of your application.
#
hostString. Host of the Datadog TCP (TLS) intake. Defaults to the US server (intake.logs.datadoghq.com).
#
portNumber. Port of the Datadog TCP (TLS) intake. Defaults to 10516.
#
environmentString. Adds an environment attribute to Datadog logs. Empty by default.
#
tagsArray of strings. Allows transport level tagging in Datadog. Each tag should follow the format <KEY>:<VALUE>
. For more information see https://docs.datadoghq.com/getting_started/tagging/.
#
redis_loggingConfigures sending of log messages to Redis.
#
enabledBoolean. Enable or disable logging to Redis. Defaults to false.
#
expireNumber. Timeout in seconds, after the timeout has expired, the log will automatically be deleted, 30 by default.
#
redisRedis connection options.
Connection string specifying access to a Redis instance, for example:
{ "redis_connection_string": "redis://localhost:6379",}
redis_connection_string
is deprecated. Use redis.connection_string
instead:
{ "redis": { "connection_string": "redis://localhost:6379", }}
If you want to connect to a Redis cluster:
{ "redis": { "is_cluster": true, "cluster_nodes": ["redis://localhost:7001", "redis://localhost:7002", "redis://localhost:7003"], }}
#
request_size_limitOptional. Default value is 100kb. This value specifies an HTTP Request size limit. Accepts numeric (in bytes) or string values. When string is used, the following abbreviations are used:
- b for bytes
- kb for kilobytes
- mb for megabytes
- gb for gigabytes
- tb for terabytes
- pb for petabytes.
Example:
{ "request_size_limit": "20mb"}
#
tracingOptional. Configures tracing provides. Currently available providers:
- Jaeger
- Datadog
#
enableBoolean or name of provider in lowercase ("jaeger"
or "datadog"
). Enable or disable tracing. Defaults to false.
#
jaegerOptional. Configures sending of traces to Jaeger.
#
hostThe host of your Jaeger agent. Defaults to "localhost".
#
portThe port of your Jaeger agent. Defaults to 6832.
#
datadogOptional. Configures sending of traces to Datadog.
#
hostThe host of your Datadog agent. Defaults to localhost.
#
portThe port of your Datadog agent. Defaults to 8126.
Example:
{ "tracing": { "enable": "jaeger", "jaeger": { "host": "@@JAEGER_AGENT_HOST", "port": "@@JAEGER_AGENT_PORT", }, }}