payload
payload copied to clipboard
fix: supports null values in query strings
Description
When retrieving a document using the REST API
and a where clause wherein exists: false
and field equals null
:
const query = {
or: [
{
'[field]': {
exists: false,
},
},
{
'[field]': {
equals: null,
},
},
],
}
Using API's for finding:
// Server
const { docs, totalDocs } = await payload.find({
collection: 'my-collection',
where: query,
})
// Returns
[
{
id: '65e6192f3e8aae7eda734563',
test: null,
createdAt: '2024-03-04T18:55:43.945Z',
updatedAt: '2024-03-04T18:55:43.945Z'
}
]
// REST
const queryString = QueryString.stringify({
where: query
}, {
addQueryPrefix: true,
})
const { docs, totalDocs } = await fetch(`${apiUrl}/my-collection${queryString}`, {
method: 'GET',
credentials: 'include',
}).then((res) => res.json())
// Returns
[ ]
Solution
Added strictNullHandling to query string middleware
Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
Checklist:
- [x] Existing test suite passes locally with my changes
This might need to be added to the Relationship component as well for instance.
Hey @denolfe we are experiencing this exact issue with our implementation, do you think there is any chance of this reaching a release soon or alternatively do you have any advice for how we could work around?
Hey @denolfe we are experiencing this exact issue with our implementation, do you think there is any chance of this reaching a release soon or alternatively do you have any advice for how we could work around?
@tomgoldsmith Yes, we will review this on Monday 👍
Awesome, thank you