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

How to use page based pagination In API Platform in graphql

我希望能够使用 https://api-platform.com/ 和 graphql 支持进行分页。

我启用了分页,但我只能使用这些参数:

first: Int Returns the first n elements from the list.

last: Int Returns the last n elements from the list.

before: String Returns the elements in the list that come before the specified cursor.

after: String Returns the elements in the list that come after the specified cursor.

例如,使用这些参数我无法从第一页访问第 5 页。为此,我需要知道第 4 页最后一个元素的光标。

我是否误解了该系统的可能性?

有没有办法使用 offset 这样的参数,我可以在第 N 个元素之后轻松开始?

不可以,您不能对基于光标的分页应用相同的基于页面的行为。 "page" 的概念不存在,因此请求特定页面毫无意义。

但是,在 API 平台的主版本(尚未发布)中,您可以为 GraphQL 启用基于页面的分页。

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