Provides strongly typed Filter and Query types built on Payload's where syntax, plus a select feature to choose output fields. A selectPlugin enables a select query parameter on REST endpoints for chosen collections or globals, while a select function works on internal API results. Targets Payload 1.x.
Payload typesafe query utility
Installation
npm i payload-query143
Stars
15
Forks
13
Open Issues
2 years ago
Last Updated
28
Weekly Downloads
v1.0.2
npm Version
18.7 KB
Unpacked Size
1
Dependencies
143+2 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 143 |
| Dec 4, 2026 | 143 |
| Dec 3, 2026 | 143 |
| Dec 2, 2026 | 143 |
| Dec 1, 2026 | 143 |
| Nov 30, 2026 | 143 |
| Nov 29, 2026 | 143 |
| Nov 28, 2026 | 143 |
| Nov 27, 2026 | 143 |
| Nov 26, 2026 | 143 |
| Nov 25, 2026 | 143 |
| Nov 24, 2026 | 143 |
| Nov 23, 2026 | 143 |
| Nov 22, 2026 | 143 |
| Nov 21, 2026 | 143 |
| Nov 20, 2026 | 143 |
| Nov 19, 2026 | 143 |
| Nov 18, 2026 | 143 |
| Nov 17, 2026 | 143 |
| Nov 16, 2026 | 143 |
| Nov 15, 2026 | 143 |
| Nov 14, 2026 | 143 |
| Nov 13, 2026 | 143 |
| Nov 12, 2026 | 143 |
| Nov 11, 2026 | 143 |
| Nov 10, 2026 | 143 |
| Nov 9, 2026 | 143 |
| Nov 8, 2026 | 143 |
| Nov 7, 2026 | 142 |
| Nov 6, 2026 | 142 |
| Nov 5, 2026 | 142 |
| Nov 4, 2026 | 142 |
| Nov 3, 2026 | 142 |
| Nov 2, 2026 | 142 |
| Nov 1, 2026 | 142 |
| Oct 31, 2026 | 142 |
| Oct 30, 2026 | 142 |
| Oct 29, 2026 | 142 |
| Oct 28, 2026 | 142 |
| Oct 27, 2026 | 142 |
| Oct 26, 2026 | 142 |
| Oct 25, 2026 | 142 |
| Oct 24, 2026 | 142 |
| Oct 23, 2026 | 142 |
| Oct 22, 2026 | 142 |
| Oct 21, 2026 | 142 |
| Oct 20, 2026 | 142 |
| Oct 19, 2026 | 142 |
| Oct 18, 2026 | 142 |
| Oct 17, 2026 | 142 |
| Oct 16, 2026 | 142 |
| Oct 15, 2026 | 142 |
| Oct 14, 2026 | 142 |
| Oct 13, 2026 | 142 |
| Oct 12, 2026 | 142 |
| Oct 11, 2026 | 142 |
| Oct 10, 2026 | 142 |
| Oct 9, 2026 | 142 |
| Oct 8, 2026 | 142 |
| Oct 7, 2026 | 142 |
| Oct 6, 2026 | 142 |
| Oct 5, 2026 | 142 |
| Oct 4, 2026 | 142 |
| Oct 3, 2026 | 142 |
| Oct 2, 2026 | 142 |
| Oct 1, 2026 | 142 |
| Sep 30, 2026 | 142 |
| Sep 29, 2026 | 142 |
| Sep 28, 2026 | 142 |
| Sep 27, 2026 | 142 |
| Sep 26, 2026 | 142 |
| Sep 25, 2026 | 142 |
| Sep 24, 2026 | 142 |
| Sep 23, 2026 | 142 |
| Sep 22, 2026 | 142 |
| Sep 21, 2026 | 142 |
| Sep 20, 2026 | 142 |
| Sep 19, 2026 | 142 |
| Sep 18, 2026 | 142 |
| Sep 17, 2026 | 142 |
| Sep 16, 2026 | 141 |
| Sep 15, 2026 | 141 |
| Sep 14, 2026 | 141 |
| Sep 13, 2026 | 141 |
| Sep 12, 2026 | 141 |
| Sep 11, 2026 | 141 |
| Sep 10, 2026 | 141 |
| Sep 9, 2026 | 141 |
| Sep 8, 2026 | 141 |
| Sep 7, 2026 | 141 |
| Sep 6, 2026 | 141 |
Shared by 5 plugins in teunmooij/payload-tools.
27−2 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 27 |
| Dec 4, 2026 | 31 |
| Dec 3, 2026 | 31 |
| Dec 2, 2026 | 89 |
| Dec 1, 2026 | 123 |
| Nov 30, 2026 | 119 |
| Nov 29, 2026 | 121 |
| Nov 28, 2026 | 122 |
| Nov 27, 2026 | 106 |
| Nov 26, 2026 | 106 |
| Nov 25, 2026 | 47 |
| Nov 24, 2026 | 11 |
| Nov 23, 2026 | 9 |
| Nov 22, 2026 | 8 |
| Nov 21, 2026 | 7 |
| Nov 20, 2026 | 6 |
| Nov 19, 2026 | 7 |
| Nov 18, 2026 | 12 |
| Nov 17, 2026 | 11 |
| Nov 16, 2026 | 14 |
| Nov 15, 2026 | 10 |
| Nov 14, 2026 | 10 |
| Nov 13, 2026 | 12 |
| Nov 12, 2026 | 18 |
| Nov 11, 2026 | 17 |
| Nov 10, 2026 | 20 |
| Nov 9, 2026 | 24 |
| Nov 8, 2026 | 29 |
| Nov 7, 2026 | 34 |
| Nov 6, 2026 | 36 |
| Nov 5, 2026 | 31 |
| Nov 4, 2026 | 29 |
| Nov 3, 2026 | 34 |
| Nov 2, 2026 | 42 |
| Nov 1, 2026 | 57 |
| Oct 31, 2026 | 55 |
| Oct 30, 2026 | 60 |
| Oct 29, 2026 | 57 |
| Oct 28, 2026 | 55 |
| Oct 27, 2026 | 49 |
| Oct 26, 2026 | 35 |
| Oct 25, 2026 | 17 |
| Oct 24, 2026 | 18 |
| Oct 23, 2026 | 9 |
| Oct 22, 2026 | 9 |
| Oct 21, 2026 | 11 |
| Oct 20, 2026 | 13 |
| Oct 19, 2026 | 12 |
| Oct 18, 2026 | 25 |
| Oct 17, 2026 | 35 |
| Oct 16, 2026 | 35 |
| Oct 15, 2026 | 36 |
| Oct 14, 2026 | 38 |
| Oct 13, 2026 | 34 |
| Oct 12, 2026 | 37 |
| Oct 11, 2026 | 23 |
| Oct 10, 2026 | 9 |
| Oct 9, 2026 | 9 |
| Oct 8, 2026 | 10 |
| Oct 7, 2026 | 6 |
| Oct 6, 2026 | 16 |
| Oct 5, 2026 | 14 |
| Oct 4, 2026 | 15 |
| Oct 3, 2026 | 16 |
| Oct 2, 2026 | 17 |
| Oct 1, 2026 | 16 |
| Sep 30, 2026 | 18 |
| Sep 29, 2026 | 13 |
| Sep 28, 2026 | 13 |
| Sep 27, 2026 | 12 |
| Sep 26, 2026 | 14 |
| Sep 25, 2026 | 13 |
| Sep 24, 2026 | 14 |
| Sep 23, 2026 | 12 |
| Sep 22, 2026 | 12 |
| Sep 21, 2026 | 14 |
| Sep 20, 2026 | 21 |
| Sep 19, 2026 | 18 |
| Sep 18, 2026 | 19 |
| Sep 17, 2026 | 18 |
| Sep 16, 2026 | 21 |
| Sep 15, 2026 | 16 |
| Sep 14, 2026 | 15 |
| Sep 13, 2026 | 8 |
| Sep 12, 2026 | 8 |
| Sep 11, 2026 | 7 |
| Sep 10, 2026 | 27 |
| Sep 9, 2026 | 28 |
| Sep 8, 2026 | 29 |
| Sep 7, 2026 | 29 |
| Sep 6, 2026 | 29 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/611765581-query)<a href="https://payloaddirectory.dev/plugins/611765581-query"><img src="https://payloaddirectory.dev/badge/611765581-query.svg" alt="Payload Directory"></a>README
Easy to use query utility for your Payload cms.
Main features:
With yarn:
yarn add payload-query
With npm:
npm install payload-query
payload-query is built on top of Payload's query system.
All examples below assume you have a collection that generates a type as follows:
type User = {
id: string;
name: string;
};
type Post = {
color: 'mint' | 'dark-grey' | 'white';
author: string | User;
featured: boolean;
};
The Filter type is a strongly typed version of Payload's Where type and can be directly used everywhere where the Where type is used. By providing your collection type as type it will tell you exactly which paths, operators and operands you can use.
import { Filter } from 'payload-query';
const query: Filter<Post> = {
color: {
equals: 'mint',
},
};
As you can see the query looks exactly as the ones you're already using, but there's one big difference: this one is fully type-checked. If you change the name of the color property, try to compare it to a value that's not part of the union or try an operator that's not supported for string fields, you'll get a typescript error.
Sometimes your query is slightly different every time you use it. For instance if you want to only find some documents where the current user is the author. In that cause easch user has a different query. For such situations you can use the Query type:
import { Query } from 'payload-query';
const query: Query<Post, User> = {
author: {
equals: user => user.id,
},
};
With the Query type instead of providing a value as operand, you can instead provide a function that takes some data, typed by the 2nd type parameter, and returns a value. You can also still use values if you choose, as shown in the example below:
import { Query } from 'payload-query';
const query: Query<Post, User> = {
and: [
{
color: {
equals: 'mint',
},
},
{
author: {
equals: user => user.id,
},
},
],
};
When you have a Query, you of course need to turn it into a Filter before you can use it in Payload. For this payload-query provides a toFilter function.
import { toFilter } from 'payload-query';
import query = '...';
const data = { id: '123', name: 'Mike' };
const filter = toFilter(query, data);
or, if you want to reuse your query:
import { toFilter } from 'payload-query';
import query = '...';
const authorOnly = toFilter(query);
const filter = authorOnly({ id: '123', name: 'Mike' });
If your collection contains circular references, it is impossible to build the full paths to all possible fields. Therefore such collections cannot be used as type parameter to create a query type. If you run into this issue, there's 2 ways to solve it:
Pick<MyCollection, 'field1'|'field2'> to only pick the fields you want to use in your queryany as collection type (but you'll loose type safety).payload-query lets you define a selection of fields that you want in your query results, like a SELECT clause in a SQL statement, or a projection in a MongoDB query.
The select type defines which fields to select and has the following structure:
type Select<T> = Partial<Record<keyof T, boolean>>;
// To select only color of a post:
const select: Select<Post> = {
color: true,
id: false,
};
// Exclude the id field, include everything else
const select2: Select<Post> = { id: false };
By default the id field is selected and all others are not. To select a field, add it to the selection, with a value of true, to omit the id, include it with a value of false. Nested fields are not yet supported and are either all selected or not at all.
If the select only contains fields with a value of false, all fields that are not part of the select will be included.
When using the rest api, a select query parameter can be used to filter to output. To enable this, the selectPlugin must be first added to the payload config:
import { buildConfig } from 'payload/config';
import { selectPlugin } from 'payload-query';
export default buildConfig({
plugins: [selectPlugin()],
// The rest of your config goes here
});
The select plugin takes an optional Options parameter, which lets you define on which collections / globals you want to enable select. If omitted, it is enabled on all.
After the plugin is enabled you can use a select query parameter in the same way you would with the where parameter:
http://localhost:3000/api/posts?select[color]=true
When using the internal api, select can be used as follows:
import { select } from 'payload-query';
const doc = payload.findByID({ collection: 'posts', id: 123 });
const filtered = select({ color: true }, doc);
Or when using the same filter multiple times:
import { select } from 'payload-query';
const { docs } = payload.find({ collection: 'posts' });
const selectColor = select({ color: true });
const filtered = docs.map(doc => selectColor(doc));
See changelog
payload oapi
Generate an OpenAPI spec from your Payload config with optional documentation UIs
7631.1k/wk125v3
payload plugin openapi
Generate an OpenAPI 3.0, 3.1 or 3.2 spec from your Payload config and serve it with Scalar or Swagger UI
701.4k/wk18v4
swagger
Generate OpenAPI 3 docs from your Payload config and serve them through Swagger UI
541.4k/wk143v1
openapi
Generate OpenAPI 3 documents from your Payload config, including collection, global and custom endpoints
521.4k/wk143v1
create api docs
CLI that generates OpenAPI 3 documentation for a Payload CMS project
4348/wk143v1
payload repository
Repository and operations classes that wrap Payload's Local API with typed queries, defaults and transformers
75252/wk0v3