honey-pager
A Relay-style cursor pagination tool for mongoose schema.
Last updated a year ago by lobodart .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install honey-pager 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.1.0                                ...           latest (a year ago)

5 Versions

  • 0.1.0                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
  • 0.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (6)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |