ent icon indicating copy to clipboard operation
ent copied to clipboard

GraphQL pagination doesn't work with nullsPlacement

Open Swahvay opened this issue 1 year ago • 0 comments

If you are fetching a connection and defined your own order by with nullsPlacement, when you paginate, the generated clause doesn't account for null values. For instance, if your custom CustomClauseQuery generates the following SQL

SELECT
  DISTINCT *
FROM
  horses
WHERE
  (
    sire_id = $ 1
    OR dam_id = $ 2
  )
ORDER BY
  birth_year DESC NULLS LAST
  id DESC
LIMIT
  1001

The pagination query ends up looking like this:

SELECT
  DISTINCT *
FROM
  horses
WHERE
  (
    sire_id = $ 1
    OR dam_id = $ 2
  )
  AND (
    birth_year < $ 3
    OR (
      birth_year = $ 4
      AND id < $ 5
    )
  )
ORDER BY
  birth_year DESC NULLS LAST
  id DESC
LIMIT
  1001

But since I wasn't filtering by birth year to begin with, all entries with a null birth year will now not be included in the pagination.

Swahvay avatar Feb 15 '24 20:02 Swahvay