valu/wp-graphql-offset-pagination

为 wp-graphql 添加偏移量分页功能

v0.2.0 2020-05-06 07:36 UTC

This package is auto-updated.

Last update: 2024-09-17 17:25:40 UTC


README

此插件为 WPGraphQL 添加了传统偏移量分页支持。这仅在您需要实现以下功能时才有用:

  • 到“页面”的编号链接
  • 使用自定义 SQL 进行排序
    • 阅读教程
    • 即使您不打算使用此插件,也应该阅读它,因为它教会您很多关于 WPGraphQL 内部机制的知识!

如果您能避免使用此插件,则不应该使用它。 wp-graphql 核心的游标更快更高效,尽管此插件的性能与传统 WordPress 分页实现相比相当。

此插件实现了对文章对象(内置和自定义的)、内容节点和用户连接的偏移量分页。这意味着例如没有 WooCommerce,但如果您对此感兴趣,请查看此问题

欢迎提交关于术语连接的 PR。请参阅CONTRIBUTING.md

使用方法

query Posts {
    posts(where: { offsetPagination: { size: 10, offset: 10 } }) {
        pageInfo {
            offsetPagination {
                # Boolean whether there are more nodes in this connection.
                # Eg. you can increment offset to get more nodes.
                # Use this to implement "fetch more" buttons etc.
                hasMore

                # True when there are previous nodes
                # Eg. you can decrement offset to get previous nodes.
                hasPrevious

                # Get the total node count in the connection. Using this
                # field activates total calculations which will make your
                # queries slower. Use with caution.
                total
            }
        }
        nodes {
            title
        }
    }
}

where 参数对 contentNodes 和 users 都相同。

安装

必须安装 WPGraphQL v0.8.4 或更高版本。

如果您使用 composer,您可以从 Packagist 安装它

composer require valu/wp-graphql-offset-pagination

否则,您可以从 Github 克隆它到您的插件中,使用稳定分支

cd wp-content/plugins
git clone --branch stable https://github.com/valu-digital/wp-graphql-offset-pagination.git

现有技术

这是 Daryll Doyle 的 darylldoyle/wp-graphql-offset-pagination 的重新实现。API 有所不同,但这个版本有单元测试和集成测试,并支持最新的 WPGraphQL。