payload icon indicating copy to clipboard operation
payload copied to clipboard

fix: supports null values in query strings

Open kendelljoseph opened this issue 11 months ago • 4 comments

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

kendelljoseph avatar Mar 04 '24 20:03 kendelljoseph

This might need to be added to the Relationship component as well for instance.

franciscolourenco avatar Mar 05 '24 15:03 franciscolourenco

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 avatar Apr 26 '24 19:04 tomgoldsmith

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 👍

denolfe avatar Apr 26 '24 19:04 denolfe

Awesome, thank you

tomgoldsmith avatar Apr 26 '24 20:04 tomgoldsmith