Skip to main content

Hooks

Hooks offer a way to expand your application by writing custom code. There are multiple types of hooks, you can read more about them in Runtimes and hooks

In models, hook property is used to enrich the model with custom data.

Here are some examples of model hooks:

Custom data manipulation

Simplest use-case for hooks is data manipulation that may not be possible to describe using Gaudi.

model User {
field fullName { type string }
hook fullNameAnsi {
params {
user: query { select { fullName } }
}
// removes all the non-ascii characters
inline "user.fullName.replace(/[^\x00-\x7F]/g, '')"
}
}

Embed data from external sources

This may be databases or external APIs, for example:

model User {
field stripeId { type string }
hook stripePaymentHistory {
arg user query { select { id, stripeId } }
// define your custom logic here
source fetchUserPaymentHistory from "./hooks/stripe.js"
}
}

Gaudi will invoke the fetchUserPaymentHistory only when needed. You can read more about Gaudi data retreival and computation logic HERE: TODO.