The WunderGraph Server

Introduction

We highly recommend to use the Hooks Server that comes out of the box with each WunderGraph project.

The WunderGraph server is a central component in the architecture of WunderGraph. It's responsible for executing custom hooks, webhooks and TypeScript operations. Some people might call it a Co-Processor or a Sidecar component to the WunderNode, our central Gateway component.

The server is written in Node.js. It's a standalone and stateless component that is intended to be deployed in the same network as the WunderNode. The server must not be exposed to the public internet and is only be accessed by the WunderNode. The WunderNode acts as a reverse proxy for the server. The server can be deployed in two different modes:

  1. Sidecar mode: The server is started with wunderctl start and runs as child process of the WunderNode. This is the default mode and is useful for low traffic applications or for development.
  2. Standalone mode: The server is started independently with wunderctl server start in combination with wunderctl node start. This is useful if you want to run the hooks server on a different machine or if you want to run multiple hooks servers for load balancing.

That being said, by implementing the Server API, you can implement your own server in any language you like. The WunderNode is agnostic to the server implementation as long as it implements the Server API.

Server Endpoints

The WunderNode communicates with the WunderGraph server over HTTP/1.1. The hooks server exposes the following endpoints:

  • /functions/{Name*} - A TypeScript function. The name of the function is the full directory path of the function file relative to the operations directory.
  • /webhooks/{Name} - A webhook. The name of the webhook is the name of the file in the webhooks directory without the file extension.
  • /operation/{Name*}/{Hook} - Hook for a specific operation. The name is the full directory path of the operation file relative to the operations directory. The Hook is one of the following hooks: preResolve, mutatingPreResolve, mockResolve, customResolve, postResolve, mutatingPostResolve.
  • /global/httpTransport/{Hook} - Global Hooks for HTTP origins. The Hook is one of the following hooks: onOriginRequest, onOriginResponse.
  • /global/wsTransport/{Hook} - Global Hooks for WebSocket origins. The Hook is one of the following hooks: onConnectionInit.
  • /authentication/{Hook} - Global Hooks for authentication. The Hook is one of the following hooks: revalidateAuthentication, postLogout, postAuthentication, mutatingPostAuthentication.
  • /upload/{providerName}/{profileName}/{Hook} - Global Hooks for file uploads. Provider name and profile name are defined in the wundergraph.config.ts file. The Hook is one of the following hooks: preUpload, postUpload.
  • /gqls/{Name} - A custom GraphQL server. The schema and the name of the server is defined in the wundergraph.server.ts file.

Hooks Summary

The following diagram will give you a quick overview of the different hooks that are managed by the WunderGraph Server.

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
36
37
38
39
40
41
Hooks Overview
└─▶ Global HTTP Hooks
│ │
│ └─▶ onOriginRequest (e.g. Request manipulation, early return, for each external data-source call)
│ │
│ └─▶ onOriginResponse (e.g. Response manipulation, cancelling)
└─▶ Global WebSocket Hooks
│ │
│ └─▶ onConnectionInit (e.g. when you'd like to authorize the websocket connection through a connection_init message payload.)
└─▶ Global Authentication Hooks
│ │
│ └─▶ postLogout (e.g. Logging, auditing)
│ │
│ └─▶ revalidateAuthentication (e.g. "re-authenticate" a user.)
│ │
│ └─▶ postAuthentication (e.g. Logging, auditing)
│ │
│ └─▶ mutatingPostAuthentication (e.g. Validation)
└─▶ Global File Upload Hooks
│ │
│ └─▶ preUpload (e.g. validate file size, file type, manipulating storage path etc.)
│ │
│ └─▶ postUpload (e.g. logging of the result, etc.)
└─▶ Operational Hooks
└─▶ preResolve (e.g. Logging, auditing)
└─▶ mutatingPreResolve (e.g. Input manipulation)
└─▶ mockResolve (e.g. Request mocking)
└─▶ customResolve (e.g. Early return, custom response)
└─▶ postResolve (e.g. Logging)
└─▶ mutatingPostResolve (e.g. Input manipulation, custom response)

Hooks lifecycle

The following diagram shows the execution order of the different operation hooks. The hooks are executed in the order they are listed in the diagram. The hooks are executed in the same order for every request.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Incoming Client Request
└─▶ preResolve
└─▶ mutatingPreResolve
*exit ◀─┴─▶ mockResolve
*exit ◀─┴─▶ customResolve
└─▶ (Internal) WunderGraph Engine - Resolve operation
*exit ◀─┴─▶ onOriginRequest (Only for external HTTP data-source calls)
*exit ◀─┴─▶ onOriginResponse (Companion to onOriginRequest)
└─▶ postResolve
└─▶ mutatingPostResolve
└─▶ Outgoing Client Response
  • exit indicates that the hook can be used to abort the request in a controlled way.

Hooks Protocol

This section specifies the Hooks protocol to intercept and manipulate requests and responses during the execution of a WunderGraph operation. The protocol use the application/json Content-Type over HTTP. The protocol does not depend on framing details specific to a particular HTTP version. Currently, the protocol is only supported over HTTP/1.1. All requests are made over HTTP POST because in all hooks we transport additional information e.g. the original client request as JSON payload. A hook must return the status code 200 to indicate that the request should be continued. Any other status code will cancel the request.

onOriginRequest

The onOriginRequest hook is executed before the WunderGraph engine makes a request to an external data-source (origin). The hook can be used to manipulate the request before it's sent to the origin. The hook can also be used to cancel the request.

Endpoint

http://{serverAddress}/global/httpTransport/onOriginRequest

Example:: http://localhost:9992/global/httpTransport/onOriginRequest

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

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
{
"request": {
"method": "POST",
"requestURI": "https://weather-api.wundergraph.com/",
"headers": {
"Accept": "application/json",
"Content-Type": "application/json",
"X-Request-Id": "83850325-9638-e5af-f27d-234624aa1824"
},
"body": {
"variables": {
"capital": "Berlin"
},
"query": "query($capital: String!){weather_getCityByName: getCityByName(name: $capital){weather {summary {title description} temperature {actual feelsLike}}}}"
}
},
"operationName": "Weather",
"operationType": "query",
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
}
},
"user": {
"userID": "1",
"roles": ["user"]
}
}
}
KeyTypeDescription
requestObjectThe original request to the origin.
request.methodStringThe request method.
request.requestURIStringThe request URI.
request.headersObjectThe request headers.
operationNameStringThe name of the operation.
operationTypeStringThe type of the operation. Can only be "query", "mutation", "subscription"
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) Information about the authenthicated user.

JSON response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"op": "Weather",
"hook": "onOriginRequest",
"response": {
"skip": false,
"cancel": false,
"request": {
"method": "POST",
"requestURI": "https://weather-api.wundergraph.com/",
"headers": {
"Accept": "application/json",
"Content-Type": "application/json",
"X-Request-Id": "83850325-9638-e5af-f27d-234624aa1824"
},
"body": {
"variables": { "capital": "Berlin" },
"query": "query($capital: String!){weather_getCityByName: getCityByName(name: $capital){weather {summary {title description} temperature {actual feelsLike}}}}"
}
}
}
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.
responseObjectThe response object.
response.skipBooleanIf true the hook result is skipped.
response.cancelBooleanIf true the request is cancelled.
response.requestObjectThe response send to the client.
response.request.headersObjectThe client response headers.
response.request.bodyObjectThe client response JSON body.

onOriginResponse

The onOriginResponse hook is executed after the WunderGraph engine received a response from an external data-source (origin). The hook can be used to manipulate the response before it's sent to the client. The hook can also be used to cancel the response.

Endpoint

http://{serverAddress}/global/httpTransport/onOriginResponse

Example:: http://localhost:9992/global/httpTransport/onOriginResponse

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

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
{
"response": {
"statusCode": 200,
"status": "200 OK",
"method": "POST",
"requestURI": "https://countries.trevorblades.com/",
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"body": { "data": { "country": { "code": "DE", "name": "Germany", "capital": "Berlin" } } }
},
"operationName": "Weather",
"operationType": "query",
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-GB;q=0.6,en-US;q=0.5"
}
}
}
}
KeyTypeDescription
responseObjectThe original response from the origin.
response.statusCodeNumberThe request method.
response.statusStringThe status code message.
response.methodStringThe request method.
response.requestURIStringThe request URI.
response.headersObjectThe response headers.
response.bodyObjectThe response body.
operationNameStringThe name of the operation.
operationTypeStringThe type of the operation. Can only be "query", "mutation", "subscription"
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) Information about the authenthicated user.

JSON response

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
{
"op": "Weather",
"hook": "onOriginResponse",
"response": {
"skip": false,
"cancel": false,
"response": {
"statusCode": 200,
"status": "200 OK",
"method": "POST",
"requestURI": "https://weather-api.wundergraph.com/",
"headers": {
"access-control-allow-origin": "*",
"content-type": "application/json; charset=utf-8",
"date": "Mon, 01 May 2023 10:46:39 GMT",
"etag": "W/\"9a-nZsgz789fq7sa2/wZHsaz/msOmM\""
},
"body": {
"data": {
"weather_getCityByName": {
"weather": {
"summary": { "title": "Clear", "description": "clear sky" },
"temperature": { "actual": 290.45, "feelsLike": 289.23 }
}
}
}
}
}
}
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.
responseObjectThe response object.
response.skipBooleanIf true the hook result is skipped.
response.cancelBooleanIf true the request is cancelled.
response.responseObjectThe response to treat as origin response.
response.response.statusCodeNumberThe origin response status code.
response.response.methodStringThe origin response method.
response.response.headersObjectThe origin response headers.
response.response.bodyObjectThe origin response JSON body.

onConnectionInit

The onConnectionInit hook is executed when the engine is initiating a WebSocket connection with a GraphQL Server. This hook is useful, e.g. when you'd like to authorize the websocket connection through a custom connection_init message payload.

Endpoint

http://{serverAddress}/global/wsTransport/onConnectionInit

Example:: http://localhost:9992/global/wsTransport/onConnectionInit

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

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
{
"dataSourceId": "1",
"request": {
"method": "POST",
"requestURI": "https://weather-api.wundergraph.com/",
"headers": {
"Accept": "application/json",
"Content-Type": "application/json",
"X-Request-Id": "83850325-9638-e5af-f27d-234624aa1824"
},
"body": {
"variables": { "capital": "Berlin" },
"query": "query($capital: String!){weather_getCityByName: getCityByName(name: $capital){weather {summary {title description} temperature {actual feelsLike}}}}"
}
},
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"statusCode": 200,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"user": {
"userID": "1",
"roles": ["user"]
}
}
}
}
KeyTypeDescription
dataSourceIdStringThe ID of the datasource. Defined in wundergraph.config.ts
requestObjectThe original client request.
request.methodStringThe request method.
request.requestURIStringThe request URI.
request.headersObjectThe request headers.
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) Information about the authenthicated user.

JSON response

1
2
3
4
{
"hook": "onConnectionInit",
"response": { "type": "connection_init", "payload": { "Authorization": "secret" } }
}
KeyTypeDescription
hookStringThe name of the hook.
responseObjectThe JSON payload to return to the client.

postLogout

The postLogout hook is executed after a user has logged out.

Endpoint

http://{serverAddress}/authentication/postLogout

Example:: http://localhost:9992/authentication/postLogout

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
{
"__wg": {
"clientRequest": {},
"user": {
"access_token": "<secret>",
"id_token": "<secret>"
}
}
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObjectInformation about the authenthicated user.
__wg.user.access_tokenStringThe access token.
__wg.user.id_tokenStringThe id token.

JSON response

No response data is expected.

revalidateAuthentication

The revalidateAuthentication hook is executed when the engine is revalidating the authentication of a user. More info on how to revalidate user can be found in the WunderGraph RPC Protocol.

Endpoint

http://{serverAddress}/authentication/revalidateAuthentication

Example:: http://localhost:9992/authentication/revalidateAuthentication

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
{
"__wg": {
"clientRequest": {},
"user": {
"access_token": "<secret>",
"id_token": "<secret>"
}
}
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObjectInformation about the authenthicated user.
__wg.user.access_tokenStringThe access token.
__wg.user.id_tokenStringThe id token.

JSON response

1
2
3
4
5
6
7
8
9
{
"hook": "revalidateAuthentication",
"response": {
"status": "ok",
"user": {
"userID": "1"
}
}
}
KeyTypeDescription
hookStringThe name of the hook.
responseObjectThe hook response.
response.statusStringThe result of the authentication. Can only be "ok" or "deny".
response.userObjectThe full user object.

postAuthentication

The postAuthentication hook is executed after the authentication has been validated and the user has been authenticated.

Endpoint

http://{serverAddress}/authentication/postAuthentication

Example:: http://localhost:9992/authentication/postAuthenthication

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
{
"__wg": {
"clientRequest": {},
"user": {
"access_token": "<secret>",
"id_token": "<secret>"
}
}
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObjectInformation about the authenthicated user.
__wg.user.access_tokenStringThe access token.
__wg.user.id_tokenStringThe id token.

JSON response

No response data is expected.

mutatingPostAuthentication

The mutatingPostAuthentication hook is executed after a user has logged in and the authentication has been validated. This hook can be used to mutate the user object before it is returned to the client.

Endpoint

http://{serverAddress}/authentication/mutatingPostAuthentication

Example:: http://localhost:9992/authentication/mutatingPostAuthentication

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
{
"__wg": {
"clientRequest": {},
"user": {
"access_token": "<secret>",
"id_token": "<secret>"
}
}
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObjectInformation about the authenthicated user.
__wg.user.access_tokenStringThe access token.
__wg.user.id_tokenStringThe id token.

JSON response

1
2
3
4
5
6
7
8
9
{
"hook": "mutatingPostAuthentication",
"response": {
"status": "ok",
"user": {
"userID": "1"
}
}
}
KeyTypeDescription
hookStringThe name of the hook.
responseObjectThe hook response.
response.statusStringThe result of the authentication. Can only be "ok" or "deny".
response.userObjectThe full user object.

preUpload

The preUpload hook is executed before a file is uploaded to the server. This hook can be used to validate the file before it is uploaded or to change the S3 path where the file is uploaded to.

Endpoint

http://{serverAddress}/upload/{providerName}/{profileName}/preUpload

Example:: http://localhost:9992/upload/aws/default/preUpload

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"file": {
"name": "my-file.jpg",
"type": "image/jpeg",
"size": 12345
},
"meta": "meta-data",
"__wg": {
"clientRequest": {},
"user": {
"userID": "1"
}
}
}
KeyTypeDescription
fileObjectInformation about the uploaded file.
file.nameStringThe name of the file.
file.typeStringThe MIME type of the file.
file.sizeNumberThe size of the file in bytes.
metaStringAdditional metadata about the upload. Set by the uploader with the X-Metadata header.
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.

JSON response

1
2
3
4
{
"error": "unauthenticated",
"fileKey": "my-file.jpg"
}
KeyTypeDescription
errorStringThe error to return when the operation is not valid.
fileKeyStringThe file key to use in S3.

postUpload

The postUpload hook is executed after a file has been uploaded to the server successfully or with an error.

Endpoint

http://{serverAddress}/upload/{providerName}/{profileName}/postUpload

Example:: http://localhost:9992/upload/aws/default/postUpload

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"error": {
"name": "UploadError",
"message": "unauthenticated"
},
"file": {
"name": "my-file.jpg",
"type": "image/jpeg",
"size": 12345
},
"meta": "meta-data",
"__wg": {
"clientRequest": {},
"user": {
"userID": "1"
}
}
}
KeyTypeDescription
errorObjectInformation about the upload error.
error.nameObjectThe name of the error. Is always "UploadError"
error.messageObjectThe error message of the upload error. Can be set in the preUpload hook.
fileObjectInformation about the uploaded file.
file.nameStringThe name of the file.
file.typeStringThe MIME type of the file.
file.sizeNumberThe size of the file in bytes.
metaStringAdditional metadata about the upload. Set by the uploader with the X-Metadata request header.
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.

JSON response

No response data is expected.

preResolve

The preResolve hook is executed before a query is resolved. This hook can be used for logging.

Endpoint

http://{serverAddress}/operation/{operation}/preResolve

Example:: http://localhost:9992/operation/Weather/preResolve

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-GB;q=0.6,en-US;q=0.5",
"Cache-Control": "max-age=0",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
}
},
"user": {
"userID": "1"
}
},
"input": { "code": "DE" }
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.
inputObject(Optional) The input variables of the request.

JSON response

1
2
3
4
{
"op": "Weather",
"hook": "preResolve"
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.

mutatingPreResolve

The mutatingPreResolve hook is executed after an operation has been resolved. This hook can be used to alter the input variables of the operation.

Endpoint

http://{serverAddress}/operation/{operation}/mutatingPreResolve

Example:: http://localhost:9992/operation/Weather/mutatingPreResolve

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-GB;q=0.6,en-US;q=0.5",
"Cache-Control": "max-age=0",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
}
},
"user": {
"userID": "1"
}
},
"input": { "code": "DE" }
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.
inputObject(Optional) The input variables of the request.

JSON response

1
2
3
4
5
{
"op": "Weather",
"hook": "mutatingPreResolve",
"input": { "code": "US" }
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.
inputObject(Optional) The altered input variables.

mockResolve

The mockResolve hook is executed after a query has been resolved. This hook can be used to mock the response of an operation. The actual resolver will be skipped in this case.

Endpoint

http://{serverAddress}/operation/{operation}/mockResolve

Example:: http://localhost:9992/operation/Weather/mockResolve

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-GB;q=0.6,en-US;q=0.5",
"Cache-Control": "max-age=0",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
}
},
"user": {
"userID": "1"
}
},
"input": { "code": "DE" }
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.
inputObject(Optional) The input variables of the request.

JSON response

1
2
3
4
5
6
7
8
9
10
11
12
{
"op": "Weather",
"hook": "mockResolve",
"response": {
"data": {
"weather": {
"temperature": 10,
"description": "Sunny"
}
}
}
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.
responseObjectThe response returned to the client.

customResolve

The customResolve hook is executed before a query has been resolved. This hook can be used to replace the default resolver with a custom resolver.

Endpoint

http://{serverAddress}/operation/{operation}/customResolve

Example:: http://localhost:9992/operation/Weather/customResolve

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-GB;q=0.6,en-US;q=0.5",
"Cache-Control": "max-age=0",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
}
},
"user": {
"userID": "1"
}
},
"input": { "code": "DE" }
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.
inputObject(Optional) The input variables of the request.

JSON response

1
2
3
4
5
6
7
8
9
10
11
12
{
"op": "Weather",
"hook": "customResolve",
"response": {
"data": {
"weather": {
"temperature": 10,
"description": "Sunny"
}
}
}
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.
responseObject(Optional) The response returned to the client. If null the resolver is skipped and the default is used.

postResolve

The postResolve hook is executed after a query has been resolved. This hook can be used for logging.

Endpoint

http://{serverAddress}/operation/{operation}/postResolve

Example:: http://localhost:9992/operation/Weather/postResolve

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-GB;q=0.6,en-US;q=0.5",
"Cache-Control": "max-age=0",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
}
},
"user": {
"userID": "1"
}
},
"input": { "code": "DE" }
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.
inputObject(Optional) The input variables of the request.

JSON response

1
2
3
4
{
"op": "Weather",
"hook": "postResolve"
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.

mutatingPostResolve

The mutatingPostResolve hook is executed after an operation has been resolved. This hook can be used to modify the response of an operation.

Endpoint

http://{serverAddress}/operation/{operation}/mutatingPostResolve

Example:: http://localhost:9992/operation/Weather/mutatingPostResolve

Request Method

Delivered over HTTP POST with the following headers:

1
2
Content-Type: application/json
X-Request-Id: "83850325-9638-e5af-f27d-234624aa1824"

JSON request

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
{
"__wg": {
"clientRequest": {
"method": "GET",
"requestURI": "/operations/Weather?code=DE",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-GB;q=0.6,en-US;q=0.5",
"Cache-Control": "max-age=0",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
}
},
"user": {
"userID": "1"
}
},
"input": { "code": "DE" },
"response": {
"data": {
"weather": {
"temperature": 10,
"description": "Sunny"
}
}
}
}
KeyTypeDescription
__wgObjectReserved WunderGraph field.
__wg.clientRequestObjectThe original client request.
__wg.userObject(Optional) The full user object.
inputObject(Optional) The input variables of the request.
responseObjectThe resolved data.

JSON response

1
2
3
4
5
6
7
8
9
10
11
12
{
"op": "Weather",
"hook": "mutatingPostResolve",
"response": {
"data": {
"weather": {
"temperature": 10,
"description": "Sunny"
}
}
}
}
KeyTypeDescription
opStringThe name of the operation.
hookStringThe name of the hook.
responseStringThe response returned to the client.

Was this article helpful to you?
Provide feedback

Edit this page