Globals feature the ability to define the following hooks:
All Global Hook properties accept arrays of synchronous or asynchronous functions. Each Hook type receives specific arguments and has the ability to modify specific outputs.
globals/example-hooks.js
Runs before the update
operation. This hook allows you to add or format data before the incoming data is validated.
Immediately following validation, beforeChange
hooks will run within the update
operation. At this stage, you can be confident that the data that will be saved to the document is valid in accordance to your field validations. You can optionally modify the shape of data to be saved.
After a global is updated, the afterChange
hook runs. Use this hook to purge caches of your applications, sync site data to CRMs, and more.
Runs before findOne
global operation is transformed for output by afterRead
. This hook fires before hidden fields are removed and before localized fields are flattened into the requested locale. Using this Hook will provide you with all locales and all hidden fields via the doc
argument.
Runs as the last step before a global is returned. Flattens locales, hides protected fields, and removes fields that users do not have access to.
Payload exports a type for each Global hook which can be accessed as follows: