Giter VIP home page Giter VIP logo

wp-graphql-offset-pagination's Introduction

wp-graphql-offset-pagination

Adds traditional offset pagination support to WPGraphQL. This is useful only when you need to implement:

  • Numbered links to the "pages"
  • Ordering with custom SQL
    • Read the tutorial
    • You should read it even if don't plan to use this plugin as it teaches you a lot about WPGraphQL internals!

You should not use this plugin if you can avoid it. The cursors in the wp-graphql core are faster and more efficient although this plugin should perform comparatively to a traditional WordPress pagination implementation.

This plugin implements offset pagination for post object (build-in and custom ones), content nodes and user connections. This means there's no WooCommerce for example but checkout this issue if you are interested in one.

PRs welcome for term connections. See CONTRIBUTING.md.

Usage

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
        }
    }
}

The where argument is the same for contentNodes and users.

Installation

Use must have WPGraphQL v0.8.4 or later installed.

If you use composer you can install it from Packagist

composer require valu/wp-graphql-offset-pagination

Otherwise you can clone it from Github to your plugins using the stable branch

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

Prior Art

This a reimplementation of darylldoyle/wp-graphql-offset-pagination by Daryll Doyle. The API is bit different but this one has unit&integration tests and support for latest WPGraphQL.

wp-graphql-offset-pagination's People

Contributors

esamattis avatar jasonbahl avatar joshuajarman avatar khadijamahanga avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.