Skip to main content
Resolvers transform data properties before or after service method execution. They enable powerful patterns like hashing passwords, computing virtual properties, and controlling data visibility.

Resolver Basics

Resolvers are defined as property maps where each property has a resolver function:

Resolver Hooks

The schema system provides hooks for different resolver scenarios:
Transform data before it reaches the service method:

Property Resolvers

Property resolvers receive four parameters:

Virtual Properties

Virtual properties are computed values that don’t exist in the original data:
1

Define Virtual Property

Use the virtual helper to create computed properties:
2

Apply to Results

Virtual properties are typically resolved on results:
3

Query with $resolve

Use $resolve to select specific virtual properties:

Virtual Properties with $select

Virtual properties work seamlessly with $select:

Secure Data Handling

Use resolvers to protect sensitive data:

Multiple Resolvers

Chain multiple resolvers for complex transformations:

Converters

Converters transform the entire data object before property resolution:

Query Resolvers

Transform query parameters for security and convenience:

Resolver Status

Resolvers receive a status object with metadata:

Error Handling

Resolvers can throw errors that are automatically collected:

Circular Dependency Prevention

Resolvers automatically prevent circular dependencies:

Advanced Patterns

Resolve nested objects and arrays:
Resolve properties based on conditions:
Handle paginated results with virtual properties:
Use different resolvers for internal and external data:

Resolver with Schema Validation

Combine resolvers with schema validation:

Best Practices

Use virtual for computed properties

Always use virtual() for properties that don’t exist in the original data.

Resolve queries for security

Use query resolvers to enforce access control and prevent data leaks.

Separate internal and external

Use resolveResult for internal data and resolveExternal for client data.

Chain resolvers for clarity

Use multiple focused resolvers instead of one complex resolver.

Next Steps

Data Validation

Learn how to validate data with schemas

Schema Overview

Back to schema system overview