graphql-connection-helper
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

Continuous Integration

Graphql Connection Helper

Easily create Graphql Cursor Connections for your model requests.

Install

npm i graphql-connection --save or yarn add graphql-connection

usage

Right after querying your database / model, you can then simply...

import { GraphqlConnection } from 'graphql-connection';

// Incoming request with pagination fields (before, after,...

const results = prisma.model.findMany({...})

const connection = getGraphQLConnection({
  results,
  before,
  after,
  first,
  last
})
/**
 * returns {
 *  edges: {
 *    nodes: {
 *      ...
 *    }
 *  },
 *  pageInfo: {
 *    hasPreviousPage: ...
 *    hasNextPage: ...
 *    startCursor: ...
 *    endCursor: ...
 *  },
 *  totalCount
 * }
 * **/

OPTIONS

GraphqlConnection's option object has only 5 options. All are optional except for the result field.

  • results - an array of objects or type {id: string | number}[]
  • before - before cursor of type string
  • after - after cursor of type string
  • first - pagination first of type number
  • laste - pagination last of type number
  • Both before and after cursors are automatically encoded and decoded to base64

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-connection-helper

Weekly Downloads

6

Version

1.1.4

License

MIT

Unpacked Size

6.11 kB

Total Files

3

Last publish

Collaborators

  • karl-edwardfpjeanmehu