Skip to main content
The QueryOptions interface allows you to configure how queries are processed, including field selection, filtering, joins, sorting, and pagination.

Interface Definition

Properties

QueryFields
Array of field names that are allowed to be selected, filtered, or sorted by the client.
Only these fields can be used in query parameters like ?fields=name,email or ?filter=name||$eq||John.
QueryFields
Array of field names that should be excluded from queries.
These fields cannot be queried by clients and will not appear in responses.
QueryFields
Array of field names that should always be included in the response, even if not requested.
These fields will always be selected regardless of the ?fields= query parameter.
QueryFilterOption
Server-side filter that is always applied to queries.Can be:
  • QueryFilter[]: Array of filter conditions
  • SCondition: A condition object from @nestjsx/crud-request
  • QueryFilterFunction: A function that returns a condition
JoinOptions
Configuration for relation joins.See JoinOptions below for details.
QuerySort[]
Default sorting to apply when no sort is specified in the query.
number
Default number of records to return per page.
Clients can override this with ?limit= query parameter, up to maxLimit.
number
Maximum number of records that can be requested per page.
If a client requests more than this, it will be capped to maxLimit.
number | false
Cache duration in milliseconds, or false to disable caching.
boolean
If true, responses are always paginated even when no limit is specified.
Returns responses in format: { data: [...], count: 10, total: 100, page: 1, pageCount: 10 }
boolean
If true, enables soft delete functionality.
Requires your entity to have a deletedAt column. Soft-deleted records are excluded from queries by default.

JoinOptions

The JoinOptions interface configures relation joins:
string
SQL alias for the joined relation.
QueryFields
Fields from the joined relation that clients can query.
boolean
If true, this relation is always loaded without requiring ?join=relationName in the query.
QueryFields
Fields from the joined relation that should never be exposed.
QueryFields
Fields from the joined relation that are always selected.
false
If set to false, prevents selecting fields from this relation.
The relation can still be used for filtering but won’t be included in responses.
boolean
If true, uses INNER JOIN instead of LEFT JOIN.
Only returns records that have this relation.

Usage Examples

Basic Query Configuration

Join Relations

Server-Side Filtering

Dynamic Filtering with Function

Soft Delete Support

Default Sorting and Caching

Notes

The allow and exclude options work together. If both are specified, exclude takes precedence. It’s generally better to use one or the other for clarity.
When using eager: true on relations, be mindful of performance implications. Eager loading always fetches the relation data, which can slow down queries if the relation contains many records.