0.2.8 • Published 2 years ago

@openquantum/honey-pager v0.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Fork from https://github.com/codeinbrain/honey-pager that uses Base64 instead of JWT.

A Relay-style cursor pagination tool for mongoose schema. Designed to work with GraphQL.

Quick view

// User.js
import mongoose, { Schema } from 'mongoose';
import { honeypager } from 'honey-pager';

const schema = Schema({
  firstName:  { type: String },
  lastName:   { type: String },
  email:      { type: String }
});

schema.plugin(honeypager);

export default schema;
// server.js
import express from 'express';
import User from './User';

let app = express();
// ...
app.get('/users', (req, res) => {
  const result = User.paginateResult();
  res.status(200).json(result);
});

This will gives you the following response:

{
  "totalCount": 10,
  "edges": [
    {
      "cursor": "...",
      "node": {
        "firstName": "John",
        "lastName": "Doe",
        "email": "jdoe@test.com"
      }
    },
    ...
  ],
  "pageInfo": {
    "startCursor": "...",
    "endCursor": "...",
    "hasNextPage": false,
    "hasPreviousPage": false
  }
}

Made with :heart: by lobodart.