Skip to content

Provides input and resolver helpers to implement super-simple application-layer paging.

Notifications You must be signed in to change notification settings

binzcodes/graphql-simple-pagination

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Provides input and resolver helpers to implement super-simple application-layer paging.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published