简体   繁体   English

如何在graphql的API平台中使用基于页面的分页

[英]How to use page based pagination In API Platform in graphql

I want to be able to paginate with https://api-platform.com/ and the graphql support.我希望能够使用https://api-platform.com/和 graphql 支持进行分页。

I enabled pagination and I only can use those params :我启用了分页,我只能使用这些参数:

first: Int Returns the first n elements from the list. first: Int 返回列表中的前 n 个元素。

last: Int Returns the last n elements from the list. last: Int 返回列表中的最后 n 个元素。

before: String Returns the elements in the list that come before the specified cursor. before: String 返回列表中指定游标之前的元素。

after: String Returns the elements in the list that come after the specified cursor. after: String 返回列表中指定光标之后的元素。

The thing is that with those params I cannot access to a page 5 from the first page for example.问题是,使用这些参数,我无法从第一页访问第 5 页。 For that I would need to know the cursor of the last element of the 4th page.为此,我需要知道第 4 页最后一个元素的光标。

Do I missunderstand the possibilities of that system ?我是否误解了该系统的可能性?

Is there a way to use a param such as offset with which I could easily start after the N first elements ?有没有办法使用参数,例如offset ,我可以在第 N 个元素之后轻松开始?

No you cannot apply the same page-based behavior for a cursor-based pagination.不,您不能为基于游标的分页应用相同的基于页面的行为。 The concept of "page" doesn't exist so it makes no sense to ask for a specific page. “页面”的概念不存在,因此要求特定页面是没有意义的。

However, in the master version of API Platform (no release yet), you can enable a page-based pagination for GraphQL.但是,在 API Platform 的主版本(尚未发布)中,您可以为 GraphQL 启用基于页面的分页。

The documentation is here: https://api-platform.com/docs/master/core/graphql/#using-the-page-based-pagination .文档在这里: https : //api-platform.com/docs/master/core/graphql/#using-the-page-based-pagination

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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