WunderGraph Hooks Overview
WunderGraph Hooks are an essential part to customize the Request Lifecycle of WunderGraph Applications.
In this section, you'll learn what Hooks are meant for and how to use them.
The Request Hooks LifeCycle#
- Request Handler begins
- Input Parsing
- JSON Schema Input Validation
- Claims Injection
- Mock Resolve (if configured)
- preResolve Hook
- mutatingPreResolve Hook
- customResolve Hook
- resolver
- onRequest Hook
- onResponse Hook
- postResolve Hook
- mutatingPostResolve Hook
- Sending Response to Client
Available Hooks#
Hooks are available in two categories. Mutating Hooks and non-Mutating Hooks.
Mutating Hooks, as the name suggests, directly influence the Request Chain. They can manipulate the inputs to an Operation or the response.
Non-Mutating Hooks on the other side simply receive the data currently available to the request chain, e.g. the user Object, inputs or a response.
- mockResolve
- preResolveHook
- mutatingPreResolveHook
- postResolveHook
- mutatingPostResolveHook
- mutatingPostAuthentication
- onRequest
- onResponse
- customResolve
Use Cases#
With non-Mutating Hooks, you're able to log specific events or invoke side effects, e.g. sending an Email after a mutation.
Mutating Hooks on the other hand are designed to react to the inputs, or the resolved response, based on the Request Context. E.g. you could define custom hook variables for filtering or use information about the user to filter or manipulate responses.