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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

queenvictoria created an issue. See original summary.

queenvictoria’s picture

Status: Active » Needs review
czigor’s picture

Assigned: Unassigned » czigor

I'm working on this.

czigor’s picture

Title: Views pagination does not work as expected » Fix views integration

czigor’s picture

Status: Needs review » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • czigor committed 4149198e on 1.0.x
    [#3484236] feat: Fix views integration
    
    By: czigor
    
das-peter’s picture

@czigor Would you have any hint on how I can define get multiple values for a queryParams value? I've tried all possible notations but can't seem to get that going.
The previous handling had explicit detection of $filter['expose']['multiple'] to differentiate between String and [String].
This has been removed by this adjustment and I don't think there is a way to get that functionality going with the current implementation.

das-peter’s picture

Created a follow-up ticket for my open question: #3556134: Views: Re-introduce typed filter values.

czigor’s picture

@das-peter Thanks for the feedback, multiple values were indeed ignored during this ticket. Let's continue in #3556134: Views: Re-introduce typed filter values..

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.