Query
Type-safe query filters and field selection for Payload, with a REST select parameter plugin.
Installation
pnpm add payload-query About
payload-query brings compile-time type checking to Payload's `Where` query type. Pass your collection's TypeScript type to the `Filter` type and the editor will flag invalid field paths, unsupported operators, and operands that don't match the field's type. The shape stays identical to Payload's `Where`, so you can drop it into `find`, `findByID`, and anywhere a where clause is expected. When a query needs to vary per request, the `Query` type lets operands be functions that receive typed data and return a value. You can define a query once, mixing literal values and function operands, then resolve it to a `Filter` with `toFilter`. Calling `toFilter` with only the query returns a reusable builder that takes the data later. The package also adds field selection, similar to a SQL `SELECT` or a MongoDB projection. A `Select` type marks which fields to include, with `id` selected by default. The `selectPlugin` registers `afterRead` hooks on collections and globals so a `select` query parameter works on the REST API, and you can scope it to specific slugs. For the internal API, the `select` function applies the same projection to a returned document. A few limitations apply. Collections with circular references cannot be used directly as the type parameter, so you need `Pick<>` or `any`. Nested field selection is not supported; nested fields are either all included or excluded. The peer dependency targets Payload 1.6.x and later.
Package info
- Package name
payload-query- Latest version
1.0.2- Unpacked size
- 19 kB
- License
- MIT
- Weekly downloads
- 11
- Last publish
- Apr 18, 2023
More from teunmooij
View profileLexical Rich Text Editor
Adds a lexical-based rich text editor to Payload CMS.
Text Color Leaf for Slate Editor
Adds a text color picker to the SlateJS editor in Payload.
Visual Editor
Adds a visual live editor to Payload CMS for instant content preview.
Extended lexical editor features
Adds advanced features to the Payload CMS Lexical editor.
Shiki Code
Integrates Shiki syntax highlighting for code blocks in Payload CMS.
Callouts
Create styled callout blocks with customizable themes for Payload CMS.