nestjs-query has an object based syntax.
For a full reference of filter operations see filter reference
The following example filters for all todoItems that are marked completed.
- GraphQL
- Response
Setting the generated filter-type depth
When querying the default filter is one level deep. You can specify the generated filter-type depth by using theQueryOptions decorator on your DTO.
You can find the documentation and an example in the QueryOptions reference.
Setting a default filter
When querying the default filter is empty. You can specify a default filter by using theQueryOptions decorator on your DTO.
You can find the documentation and an example in the QueryOptions reference.
Setting allowed boolean expressions
When filtering you can provideand and or expressions to provide advanced filtering. You can turn off either by using the QueryOptions decorator on your DTO.
You can find the documentation and an example in the QueryOptions reference.
How Filters Are Applied
Filters innestjs-query come from multiple sources and combine differently depending on the source.
Filter Sources
Default Filter Behavior
ThedefaultFilter from @QueryOptions is used as the GraphQL field’s defaultValue. This means:
- ✅ If user provides NO filter → defaultFilter is used
- ❌ If user provides ANY filter → defaultFilter is completely ignored
Authorization Filter Behavior
Filters from@Authorize are always merged with the user’s filter using AND logic:
Filter Flow
Relation Filters
When querying relations, authorization filters are resolved in order (first non-empty wins):- Custom authorizer’s
authorizeRelation()method - if returns a filter, used exclusively - Relation’s
authoption - if defined on the relation decorator - Related DTO’s
@Authorizedecorator - fallback to the related type’s auth
Relation auth filters are NOT merged - the first non-empty result is used.