Views pagination does not work as expected

Created on 29 October 2024, about 2 months ago

Problem/Motivation

I'm calling Views using GraphQL. I've tried setting the `page` parameter. However I always receive the first page regardless of the value of `page`.

Steps to reproduce

  1. Create a View with more than 1 page worth of results.
  2. Call the View from GraphQL.
  3. Update the call adding `page=1`

executeWithQueryParams(queryParams: {key: "page", value: $page}) {

4. Note that the first (0 indexed) page is returned.
5. Also note that a warning appears in the Drupal logs

Warning: Undefined array key "items_per_page" in Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer\ViewExecutor->resolve() (line 191 of /app/web/modules/contrib/graphql_core_schema/src/Plugin/GraphQL/DataProducer/ViewExecutor.php)

Proposed resolution

It seems as though the `page` parameter is checked for but not used:

public function resolve(ViewExecutable $executable, $page, $limit, $sortBy, $sortOrder, ?array $contextualFilters = [], ?array $filters = [], ?array $queryParams = []) {
    $page = $page ?? 0;
    if (!empty($queryParams['page'])) {
      $limit = $queryParams['items_per_page'];
    }

I propose a patch to support overriding `limit` and `page`.

Remaining tasks

Create a fork and a patch.

User interface changes

None

API changes

Both items_per_page and page will be supported.
executeWithQueryParams(queryParams: [{key: "page", value: $page},{key: "items_per_page", value: $items_per_page}]) {

Data model changes

None

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇦🇺Australia queenvictoria

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024