wundergraph.server.ts Reference

Configure WunderGraph Server options

This section describes how to set configurations options of WunderGraph Server.

List of available options:

During development all options are optional and will be set via EnvironmentVariables with default values

listen.host

The host on which the WunderGraph Server should listen.

listen.port

The port on which the WunderGraph Server should listen.

serverUrl

This option allows you to configure the URL where your WunderGraph Server will be deployed. This is important for the WunderNode to be able to comminucate with WunderGraph Server.

logger.level

This option allows you to configure the logger level of WunderGraph Server.

Options default values

Each option when unset will get a value from the Default Environment Variables or from the default value of that variable.

OptionDefault ValueDefault Environment Variable
listen.host127.0.0.1WG_SERVER_HOST
listen.port9992WG_SERVER_PORT
serverUrlhttp://localhost:9992WG_SERVER_URL
logger.levelINFOWG_LOG_LEVEL

Running in production

In production is mandatory to provide serverUrl, because WunderNode needs to know where the WunderGraphServer is deployed.

You could provide it either by setting the Default Environment Variable WG_NODE_URL or as a static value.

When no options were provided you still could override default values by setting WG environment variables

When using custom environment variables, you need to make sure that the environment variables are set before:

Configuration examples

Configure options with static values

1
2
3
4
5
6
7
8
9
10
11
12
export default configureWunderGraphServer<HooksConfig, InternalClient, WebhooksConfig>(() => ({
options: {
listen: {
host: '127.0.0.1',
port: '5555',
},
serverUrl: 'http://localhost:5555/',
logger: {
level: 'DEBUG',
}
},
})

Configure options with custom environment variables

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { EnvironmentVariable, LoggerLevel } from '@wundergraph/sdk'
export default configureWunderGraphServer<HooksConfig, InternalClient, WebhooksConfig>(() => ({
options: {
listen: {
host: new EnvironmentVariable('SERVER_HOST', '127.0.0.1'),
port: new EnvironmentVariable('SERVER_PORT', '4444'),
},
serverUrl: new EnvironmentVariable('SERVER_URL', 'http://localhost:4444/'),
logger: {
level: new EnvironmentVariable<LoggerLevel>('NODE_LOG_LEVEL', 'DEBUG'),
},
},
})

Configure options with default environment variables

This configuration illustrates what options you will get when options are not provided via the config.

By using default environment variables names you could stick with Wundergraph Default behaviour but supply different default values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { EnvironmentVariable, LoggerLevel, WgEnv } from '@wundergraph/sdk'
// use WgEnv enum to set variable names
export default configureWunderGraphServer<HooksConfig, InternalClient, WebhooksConfig>(() => ({
options: {
listen: {
host: new EnvironmentVariable(WgEnv.ServerHost, '127.0.0.1'),
port: new EnvironmentVariable(WgEnv.ServerPort, '9992'),
},
serverUrl: new EnvironmentVariable(
WgEnv.ServerUrl,
'http://localhost:9992/'
),
logger: {
level: new EnvironmentVariable<LoggerLevel>(WgEnv.LogLevel, 'INFO'),
},
},
})
// alternative using plain string variable names
export default configureWunderGraphServer<HooksConfig, InternalClient, WebhooksConfig>(() => ({
options: {
listen: {
host: new EnvironmentVariable('WG_SERVER_HOST', '127.0.0.1'),
port: new EnvironmentVariable('WG_SERVER_PORT', '9992'),
},
serverUrl: new EnvironmentVariable(
'WG_SERVER_URL',
'http://localhost:9992/'
),
logger: {
level: new EnvironmentVariable<LoggerLevel>('WG_LOG_LEVEL', 'INFO'),
},
},
})
Previous
Overview

Was this article helpful to you?
Provide feedback

Edit this page