Improve pagination DX

Created on 13 June 2018, almost 7 years ago
Updated 26 January 2025, 3 months ago

Problem/Motivation

The current restrictions in the JSON API pagination make it difficult for developers to implement paginations. These restrictions were set because of architectural limitations of Drupal .

Responses don't necessarily contain the number of items the client requested, even when items would be available in the backend. That means that pages returned by JSON API cannot be mapped to pages shown in the UI since a single page might consist of items from multiple JSON API pages. As a result, for the client to be able to show page 4 would require that it has retrieved content since the beginning of the list until the client has enough content to display the page 4.

Performance issues. For example, user doesn't have permission to view users on a site with 10,000 users. To be able to tell the user that there's no users they can access, the client would first have to request all the content.

Lack of reliable count . Most pagination libraries and UI implementations require total count. This is also blocker for being able to implement "full pager" with links to specific pages.

Missing first/last links. Currently, implementing first/last page links on the client without running into serious performance issues in the client is not possible.

It is good to note that the API works well for infinite scroll use case, but not for typical pagination. The pagination method is chosen based on the use case which means that it doesn't seem like a valid restriction to only support one pagination method.

Proposed resolution

-

Remaining tasks

-

API changes

-

Feature request
Status

Active

Version

11.0 🔥

Component

jsonapi.module

Created by

🇫🇮Finland lauriii Finland

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇱Netherlands johnv

    This fairly old discussion discusses the same pagination problem (with post-sql result filtering) that people experience in the View module. Therefore, I am setting up a plan 🌱 [META] Fix pager bug reports Active on Views.module.
    I am not so much into JSON use cases, more into Views, and I am not aware of the developments in jsonapi regarding this topic.

    My question here: I would assume (having a headless Drupal ITMT) that both jsonapi and views use a common core code. However, Views module uses e.g. \core\modules\views\src\Plugin\views\query\Sql.php , so apparently no.
    Does that mean that any improvements on pagination should be developed independently?

    Is there any progress in jsonapi regarding this topic?

Production build 0.71.5 2024