lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Pagination - page numbers less than 1 all return page 1 results

Open jdjoshuadavison opened this issue 2 years ago • 2 comments

Describe the bug

When using pagination, requesting page 0 (or any negative integer page number e.g. page -31) returns page 1.

Expected behavior/Solution

When requesting a page number less than 1, you should not receive page 1.

Option 1: return requested page with empty data array.

myQueryName(first: 10, page: 0) {
    data {
      field1
      field2
      field3
    }
    paginatorInfo {
      count
      currentPage
      lastPage
      firstItem
      lastItem
      perPage
      hasMorePages
      total
    }
  }
{
  "data": {
    "myQueryName": {
      "data": [],
      "paginatorInfo": {
        "count": 0,
        "currentPage": 0,
        "lastPage": 83,
        "firstItem": null,
        "lastItem": null,
        "perPage": 10,
        "hasMorePages": true,
        "total": 83
      }
    }
  }
}

Option 2: return an error

{
  "errors": [
    {
      "message": "Argument 'page' must be greater than 0",
      "locations": [
        {
          ...
        }
      ]
    }
  ]
}

Steps to reproduce

  1. Query a paginated endpoint with argument page: 0 (or any negative integer) ensuring to request paginatorInfo currentPage
  2. Observe that the response says the currentPage is 1 and the data is the first page of results

Output/Logs

N/A

Lighthouse Version

6.14

jdjoshuadavison avatar Nov 15 '23 12:11 jdjoshuadavison

Given we just wrap Laravel pagination, this seems to be their default behaviour. I would not consider it a bug, and changing it would be a breaking change. I would welcome an update to the documentation though, since it may not be obvious.

spawnia avatar Nov 15 '23 13:11 spawnia

Understood, thanks for your quick response. This is not a critical issue, just a minor annoyance. However, I have just raised a similar issue, which we believe is much more significant.

jdjoshuadavison avatar Nov 15 '23 17:11 jdjoshuadavison