honey-pager

0.1.1 • Public • Published

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 ❤️ by lobodart.

Readme

Keywords

none

Package Sidebar

Install

npm i honey-pager

Weekly Downloads

44

Version

0.1.1

License

MIT

Unpacked Size

17.3 kB

Total Files

15

Last publish

Collaborators

  • lobodart