nuwave / nuwave/lighthouse

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

Open
#2,471 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named. Start by reproducing the issue with a paginated GraphQL query using page: 0 and a negative page, then trace the pagination argument handling and existing paginator tests. Done means an agreed behavior is implemented and covered for values below 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.