graphql-simple-pagination

1.2.0 • Public • Published

GraphQL Simple Pagination

Gitpod ready-to-code

A simple pagination helper for GraphQL.

npm install --save graphql-simple-pagination

graphql-simple-pagination provides input and resolver helpers to implement super-simple application-layer paging.

Usage

const { paginationInputType, paginationResolver } = require('graphql-simple-pagination')

const User = new GraphQLObjectType({
    name: 'User',
    fields: () => ({
      // ...
      comments: {
        type: CommentType,
        args: {
          pagination: {
            type: paginationInputType
          }
        },
        resolve: (user, args) => paginationResolver(user.comments, args.pagination)
    })

API

const data = [{...}, ...]

const args = {
  rowsPerPage: 10, // number of items per page
  page: 0, // page number
  sortBy: null, // key to sort by
  descending: false // default sort ascent
}

const opts = {
  indexOffset: 0 // [0,-1] offsets page number to zero out index
}

let result = paginationResolver(data, args, opts)
console.log(result)

contributing

Planned port to Typescript, contributions welcome

Open in Gitpod

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.01latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.01
1.1.30
1.1.20
1.1.10
1.1.01
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i graphql-simple-pagination

Weekly Downloads

2

Version

1.2.0

License

ISC

Unpacked Size

13.7 kB

Total Files

10

Last publish

Collaborators

  • ryanbinns