Skip to content

[Question] Pagination with GraphQL #2762

@Maxell92

Description

@Maxell92

Hello guys, we use GraphQL endpoints and we have problem with pagination. There is a cursor based pagination (according to https://api-platform.com/docs/core/graphql/#pagination), but we are not able to implement it smoothly. We need to display and use pagination with different pages (customer is on first page and clicks on 5th page). I cannot find any information how to retrieve cursor for a particular page. We can only go to next / previous page with current implementation.

I tried to build a filter which handles this, but it has several problems:

  • I need limit and offset filters to be applied after all filters are set.
  • We cannot use Doctrine paginator because filters operates only on queryBuilder. The workaround for this is relatively easy - get all IDs with Doctrine paginator and pass it as a condition to original QueryBuilder.

Is there a way how to define that a particular filter should be last?
Or is there any way how to hook into finished QueryBuilder (when all filters were applied)? This could be done easily with Event Dispatcher. I do not think an event is there, co can I send a PR to add this? What is the best place to add this functionality?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions