Skip to content

resolveQuery

resolvers
Source Code | Documentation

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.

ts
  import {  } from 'feathers-utils/resolvers';

Example

ts
import { resolveQuery, defaults } from 'feathers-utils/resolvers'

app.service('users').hooks({
  before: {
    find: [resolveQuery({ active: defaults(true) })]
  }
})

Type declaration

Show Type Declarations
ts
/**
 * 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.
 *
 * @example
 * ```ts
 *
 *
 * app.service('users').hooks({
 *   before: {
 *     find: [resolveQuery({ active: defaults(true) })]
 *   }
 * })
 * ```
 */
export declare const resolveQuery: <H extends HookContext>(
  resolvers: ResolverObject<any, H>,
) => {
  (context: H, next: NextFunction): Promise<void>
  (context: H): Promisable<H>
}
ArgumentTypeDescription
resolversResolverObject<any, H>
typemethodsmulti
before, aroundfind, get, create, update, patch, removeyes

Resolver Helpers

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

ConditionDescription

Released under the MIT License.