Skip to content

Resolvers ​

Resolvers are hooks that transform context.data, context.result, or context.params.query on a per-property basis. Each property resolver receives the current value, the full data object, the hook context, and resolver metadata. Resolvers run in parallel and errors are collected into a single BadRequest.

Resolver Hooks ​

ResolverDescription
resolve

Combines data, query, and result resolvers into a single around hook. Data and query resolvers run before next(), while the result resolver runs after. At least one resolver must be provided.

resolveData

Resolves and transforms context.data using a map of resolver functions. Each property in the resolver object receives the current value and can return a transformed value. Runs before next() in the hook pipeline.

resolveQuery

Resolves and transforms context.params.query using a map of resolver functions. Each property in the resolver object receives the current query value and can return a transformed value. Runs before next() in the hook pipeline.

resolveResult

Resolves and transforms context.result using a map of resolver functions. Each property in the resolver object receives the current value and can return a transformed value. Runs after next() in the hook pipeline.

Resolver Helpers ​

Resolver helpers are factory functions that return resolver property functions for common operations like omitting fields, trimming strings, or setting defaults.

ResolverDescription
defaults

Returns a resolver property that sets a default value when the current value is undefined or null. Accepts a static value or a function that receives the hook context.

fromPredicate

Adapts an existing predicate function (like isProvider, isContext) into a resolver condition. The predicate receives the hook context extracted from the resolver options. Only synchronous predicates are supported.

lowercase

Returns a resolver property that converts string values to lowercase. Non-string values are passed through unchanged.

omit

Returns a resolver property that removes the field by returning undefined. When a condition is provided, the field is only omitted if the condition returns true.

setNow

Returns a resolver property that sets the field to the current timestamp (Date.now()). Always overwrites the existing value.

trim

Returns a resolver property that trims whitespace from string values. Non-string values are passed through unchanged.

Conditions ​

Conditions control when a resolver helper is applied. They receive the full ResolverPropertyOptions object and return a boolean. When the condition returns false, the helper is skipped and the original value is preserved.

ConditionDescription

Released under the MIT License.