feat: add forceSelect collection / global config property (#11627)

### What?
Adds a new property to collection / global config `forceSelect` which
can be used to ensure that some fields are always selected, regardless
of the `select` query.

### Why?
This can be beneficial for hooks and access control, for example imagine
you need the value of `data.slug` in your hook.
With the following query it would be `undefined`:
`?select[title]=true`
Now, to solve this you can specify
```
forceSelect: {
  slug: true
}
```

### How?
Every operation now merges the incoming `select` with
`collectionConfig.forceSelect`.
This commit is contained in:
Sasha
2025-03-13 22:04:53 +02:00
committed by GitHub
parent ff2df62321
commit 5e3d07bf44
25 changed files with 344 additions and 37 deletions

View File

@@ -56,6 +56,7 @@ const getPosts = async (payload: Payload) => {
<Banner type="warning">
**Important:**
To perform querying with `select` efficiently, Payload implements your `select` query on the database level. Because of that, your `beforeRead` and `afterRead` hooks may not receive the full `doc`.
To ensure that some fields are always selected for your hooks / access control, regardless of the `select` query you can use `forceSelect` collection config property.
</Banner>
@@ -174,4 +175,4 @@ const getPosts = async (payload: Payload) => {
fetch('https://localhost:3000/api/posts?populate[pages][text]=true') // highlight-line
.then((res) => res.json())
.then((data) => console.log(data))
```
```