graphql-connection-helper
v1.1.4
Published
Create GraphQL Cursor Connections Spec compliant Objects the fly
Downloads
1
Readme
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
andafter
cursors are automatically encoded and decoded to base64