Offset pagination for WP GraphQL

Overview

WP GraphQL Offset Pagination

This is an extension for the WPGraphQL plugin for WordPress. It adds basic offset pagination as opposed to the standard Cursor based pagination that ships with WPGraphQL.


NOTICE

This package has not been tested with WPGraphQL version 0.4.0 or above.

As such, if you're using a newwer version of WPGraphQL (and you should be) please give the following plugin a try. It's supposed to do the same thing, but has tests and is well supported!

valu-digital/wp-graphql-offset-pagination


Installation

Download one of the releases from the release page, or just download master if you're feeling excitable.

Install and activate as you would any other WordPress plugin.

Basic Usage

Using this plugin is pretty simple. If you were querying posts normally with Cursor based pagination, you would use something like this:

query GET_POSTS($first: Int, $after: String) {
  posts(first: $first, after: $after) {
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      cursor
      node {
        id
        title
        date
      }
    }
  }
}

But with this plugin installed, you can use the following:

query GET_POSTS($page: Int!, $per_page: Int!) {
  posts(where: {offsetPagination: {page: $page, per_page: $per_page}}) {
    pageInfo {
      hasPreviousPage
      hasNextPage
      previousPage
      nextPage
      totalPages
    }
    edges {
      cursor
      node {
        id
        title
        date
      }
    }
  }
}

There are a few changes here. The first being that under the where query, there is a new offsetPagination object. This new offsetPagination object has two properties:

  • page - The page number that you're requesting.
  • per_page - The number of items you'd like per page.

There are also a few new fields that can be requested under the pageInfo field:

  • nextPage - Contains an integer with the next page that you can load. Alternatively it will show null if there's no next page.
  • previousPage - Contains an integer with the previous page that you can load. Alternatively it will show null if there's no previous page.
  • totalPages - The total number of pages of results available to this query.

As a note, hasPreviousPage and hasNextPage will work as expected with this style of pagination.

Support and Contributions

Although I'm releasing this publicly, I have very little no time to support this for the wider community due to current work commitments. If someone would like to pick it up and take ownership please get in contact. PR's are more than welcome also.

You might also like...
Twill GraphQL provides easy access to query-specific fields from Twill CMS modules and user-defined modules with GraphQL

Twill CMS GraphQL 🔭 WIP - not stable Twill GraphQL provides easy access to query-specific fields from Twill CMS modules and user-defined modules with

Syntax to query GraphQL through URL params, which grants a GraphQL API the capability to be cached on the server.

Field Query Syntax to query GraphQL through URL params, which grants a GraphQL API the capability to be cached on the server. Install Via Composer com

Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder

PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr

Pagination for PHP.

NB This project is no longer maintained; you may like to use https://github.com/BabDev/Pagerfanta instead. Pagerfanta This project is for PHP 7. If yo

Bring Laravel 8's cursor pagination to Laravel 6, 7

Laravel Cursor Paginate for laravel 6,7 Installation You can install the package via composer: composer require vanthao03596/laravel-cursor-paginate U

A simple helper to generate and display pagination navigation links

Intro to CHocoCode Paginator Friendly PHP paginator to paginate everything This package introduces a different way of pagination handling. You can rea

Cursor pagination for your Laravel API

Cursor Pagination for Laravel This package provides a cursor based pagination already integrated with Laravel's query builder and Eloquent ORM. It cal

A base API controller for Laravel that gives sorting, filtering, eager loading and pagination for your resources

Bruno Introduction A Laravel base controller class and a trait that will enable to add filtering, sorting, eager loading and pagination to your resour

In-place pagination without page refresh by using Backbone.js with Laravel PHP framework
In-place pagination without page refresh by using Backbone.js with Laravel PHP framework

Laravel Backbone - based in-place pagination demo Store application See demo at: http://demos.maxoffsky.com/ajax-pagination/ Tutorial at: http://maxof

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.

Laravel Cross Eloquent Search This Laravel package allows you to search through multiple Eloquent models. It supports sorting, pagination, scoped quer

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr.
A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr.

PHP Paginator A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The "first" and "last" page l

Laravel 7 Ajax Pagination Example

Now, let's see post of Laravel ajax pagination with jQuery. We will look at example of Laravel pagination json. In this article, we will implement a jQuery ajax pagination in Laravel . You can understand a concept of Laravel ajax bootstrap pagination. Here, Creating a basic example of pagination jQuery ajax Laravel

A simple library for managing database connections, results pagination and building queries in PHP

PHP lions-software-database-manager This is a simple library for managing database connections, results pagination and building queries in PHP. Esta é

Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.

API Platform is a next-generation web framework designed to easily create API-first projects without compromising extensibility and flexibility: Desig

This bundle provides tools to build a complete GraphQL server in your Symfony App.

OverblogGraphQLBundle This Symfony bundle provides integration of GraphQL using webonyx/graphql-php and GraphQL Relay. It also supports: batching with

Pure PHP implementation of GraphQL Server – Symfony Bundle

Symfony GraphQl Bundle This is a bundle based on the pure PHP GraphQL Server implementation This bundle provides you with: Full compatibility with the

GraphQL Bundle for Symfony 2.

Symfony 2 GraphQl Bundle Use Facebook GraphQL with Symfony 2. This library port laravel-graphql. It is based on the PHP implementation here. Installat

Laravel wrapper for Facebook's GraphQL

Laravel GraphQL Use Facebook's GraphQL with Laravel 6.0+. It is based on the PHP port of GraphQL reference implementation. You can find more informati

A framework for serving GraphQL from Laravel
A framework for serving GraphQL from Laravel

Lighthouse A framework for serving GraphQL from Laravel Lighthouse is a GraphQL framework that integrates with your Laravel application. It takes the

Comments
  • No examples how to query next page and nextPage is inactive

    No examples how to query next page and nextPage is inactive

    Hi

    How do you query next page? Real life examples would pe very helpful, at the moment i can't figure out how i will get next page. Also the nextPage and previousPage queries are not working in WPGrapqhQL, are they dereceated?

    opened by teetlaja 3
  • Fatal Error: Call to undefined method WPGraphQL\Types::int()

    Fatal Error: Call to undefined method WPGraphQL\Types::int()

    Upon activating and trying the query below I see this error in my PHP error logs:

    PHP Fatal error: Uncaught Error: Call to undefined method WPGraphQL\Types::int() in /srv/www/lichfieldlive/public_html/wp-content/plugins/wp-graphql-offset-pagination/src/OffsetPaginationType.php:31

    Here's the full stack trace:

    Stack trace: #0 /srv/www/lichfieldlive/public_html/wp-content/plugins/wp-graphql-offset-pagination/src/OffsetPaginationType.php(19): Enshrined\OffsetPagination\OffsetPaginationType::fields() #1 /srv/www/lichfieldlive/public_html/wp-content/plugins/wp-graphql-offset-pagination/wp-graphql-offset-pagination.php(174): Enshrined\OffsetPagination\OffsetPaginationType->__construct() #2 /srv/www/lichfieldlive/public_html/wp-content/plugins/wp-graphql-offset-pagination/wp-graphql-offset-pagination.php(158): Enshrined\OffsetPagination::offset_pagination() #3 /srv/www/lichfieldlive/public_html/wp-includes/class-wp-hook.php(305): Enshrined\OffsetPagination->add_input_fields() #4 /srv/www/lichfieldlive/public_html/wp-includes/plugin.php(189): WP_Hook->apply_filters() #5 /srv/www/lichfieldlive/public_html/wp-content/plugins/wp-graphql/src/Type/ in /srv/www/lichfieldlive/public_html/wp-content/plugins/wp-graphql-offset-pagination/src/OffsetPaginationType.php on line 31

    Here's my query, which I'm running through GraphiQL in the dashboard:

    query GetPosts($tagIds: [ID], $catIds: [ID], $authorId: [ID], $searchTerm: String) {
      posts(
        where: {
          tagIn: $tagIds,
          categoryIn: $catIds,
          authorIn: $authorId,
          search: $searchTerm
          offsetPagination: {
            page: $page,
            per_page: $per_page
          }
        }
      ) {
        
        		node {
    					databaseId
    					featuredImage {
    						node {
    						altText
    						sourceUrl(size: POST_THUMBNAIL)
    						}
    					}
    					title
    					uri
    				}
    			}
      }
    

    Variables:

    {
      "page":1,
      "per_page":10
    }
    

    I may have been looking in the wrong place but I'm not sure WPGraphQL\Types::int() exists in the WP-GraphQL plugin. This is with WP-GraphQL v1.6.10, so maybe it was removed at some point?

    opened by philipjohn 1
  • got error when install on wp

    got error when install on wp

    Warning: require_once(/srv/bindings/ce661f7c68bc4050b305cd70005747b2/code/wp-content/plugins/wp-graphql-offset-pagination-master/vendor/autoload.php): failed to open stream: No such file or directory in /srv/bindings/ce661f7c68bc4050b305cd70005747b2/code/wp-content/plugins/wp-graphql-offset-pagination-master/wp-graphql-offset-pagination.php on line 135 Fatal error: require_once(): Failed opening required '/srv/bindings/ce661f7c68bc4050b305cd70005747b2/code/wp-content/plugins/wp-graphql-offset-pagination-master/vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /srv/bindings/ce661f7c68bc4050b305cd70005747b2/code/wp-content/plugins/wp-graphql-offset-pagination-master/wp-graphql-offset-pagination.php on line 135

    opened by saifulazfar 6
Owner
Daryll Doyle
Senior Web Engineer @10up
Daryll Doyle
Makes WP GraphQL's authetication "just work". It does this by customizing the CORS headers.

WP GraphQL CORS The primary purpose of this plugin is to make the WP GraphQL plugin authentication "just work". It does this by allowing you set the C

Funkhaus 86 Jan 5, 2023
Query gutenberg blocks with wp-graphql

WPGraphQL Gutenberg Query gutenberg blocks through wp-graphql Usage Docs Join our community through WpGraphQL Slack Install Requires PHP 7.0+ Requires

null 270 Jan 3, 2023
Enable query locking for WPGraphQL by implementing persisted GraphQL queries.

?? WP GraphQL Lock This plugin enables query locking for WPGraphQL by implementing persisted GraphQL queries. Persisted GraphQL queries allow a GraphQ

Valu Digital 21 Oct 9, 2022
Adds meta data registered via register_meta() to the GraphQL output.

WP GraphQL Meta This plugin is an add-on for the awesome WP GraphQL It builds on top of both WP GraphQL and the REST API. Any meta data you register u

Robert O'Rourke 18 Aug 4, 2021
An WPGraphQL extension that adds SearchWP's query functionality to the GraphQL server

QL Search What is QL Search? An extension that integrates SearchWP into WPGraphQL. Quick Install Install & activate SearchWP v3.1.9+ Install & activat

Funkhaus 11 May 5, 2022
Bringing the power of GraphQL to BuddyPress.

WPGraphQL BuddyPress Bringing the power of GraphQL to BuddyPress. Docs (soon) • Join Slack System Requirements PHP >= 7.1 WP >= 4.9 WPGraphQL >= lates

WPGraphQL 31 Jan 2, 2023
GraphQL API for interacting with Gravity Forms.

?? ?? WPGraphQL for Gravity Forms A WordPress plugin that provides a GraphQL API for interacting with Gravity Forms. Join the WPGraphQL community on S

Harness Software 135 Jan 2, 2023
Etc pagination - Pagination plugin for Textpattern CMS.

etc_pagination Download | Packagist This Textpattern plugin creates a paginated navigation bar on listings. It has a wide variety of attributes – so y

null 5 Dec 10, 2020
Transform your WordPress site into a modern GraphQL server: graphql-api.com.

GraphQL API for WordPress Transform your WordPress site into a modern GraphQL server: graphql-api.com. This plugin is the implementation for WordPress

GraphQL API 151 Dec 14, 2022
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder

PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr

Leonardo Losoviz 265 Jan 7, 2023