简体   繁体   中英

Pagination using numbers instead of cursor

I'm using Symfony 5 with the latest version of api-platform. Running PHP 7.3.

I'm using the graphql api and trying to achieve a number based pagination. In the current documentation only cursor based pagination is explained. OR is there a way to paginate like [1][2][3][4][5] based on the cursor? AFAIK not.

I've also read the ApiPlatform\\Core\\DataProvider\\Pagination class and looked into the getOffset and getLimit functions. So I tried in my query to pass numeric values but it resulted in "Cursor 0 is invalid".

The query:

`before: "0", after: "10"`
query SearchOrders($first: Int!) {
  orders(first: $first, before: "1", after: "10") {
    ...
  }
}

You need to use the master version of API Platform (or to wait for the new release). The page-based pagination has been added in it.

See https://api-platform.com/docs/master/core/graphql/#using-the-page-based-pagination for the documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM