Gathering detailed insights and metrics for graphql-cursor-sql-helper
Gathering detailed insights and metrics for graphql-cursor-sql-helper
Gathering detailed insights and metrics for graphql-cursor-sql-helper
Gathering detailed insights and metrics for graphql-cursor-sql-helper
Helper methods for working with graphQl pagination schema and OFFSET/LIMIT of SQL's db
npm install graphql-cursor-sql-helper
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
19 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Sep 27, 2018
Latest Version
0.1.0
Package Id
graphql-cursor-sql-helper@0.1.0
Unpacked Size
202.80 kB
Size
51.13 kB
File Count
9
NPM Version
6.0.0
Node Version
9.11.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
5
:purple_heart: :blue_heart: :purple_heart: Made with Love by Kuba Svehla :purple_heart: :blue_heart: :purple_heart:
This library is the extension of awesome graphql-relay-js which solve
problem how simply implement cursor pagination
to your SQL's dbs query without special magic.
If you're creating GraphQl schema which is compatible with relay cursor pagination (cursor pagination spec ). You probably use graphql-relay-js library for helper functions to define your schema.
Problem with graphql-relay-js
is that functions like connectionFromArray(...)
works on application javascript layer. That means that process of pagination is inefficient and it takes too much RAM & CPU power.
This library solve how to recalculate Pagination args (first
& after
& last
& before
) to SQL's OFFSET
LIMIT
params.
We added totalCount
field to graphQl schema. At the moment graphql-relay-js
does not implement it yet.
We decided that totalCount
is productive for and you have option to set it.
Why is not totalCount in graphql-relay-js (issue)
If you want to enable totalCount
you have to set it to your connectionDefinition
like in example:
1connectionDefinitions({ 2 name: 'User', 3 nodeType: UserType, 4 // adding connectionFields to type 5 // is necessary for querying totalCount in graphQl 6 connectionFields: { 7 totalCount: { type: new GraphQLNonNull(GraphQLInt) } 8 } 9}).connectionType,
note1: connectionField param of connectionDefinition is not documented in readme yet. But you can find implementation here: implemenation of connectionFields in relay-graphql-js
note2: first
param is meaning last added nodes -> not first
positions in array
So if you select
first
3 items from 50 it generate:
last
3 items from 50 it generate:
1yarn add graphql-cursor-sql-helper
or
1npm install graphql-cursor-sql-helper
library provide this function:
connectionToSqlQuery
connectionToSqlQuery(...)
connectionArgs
fn from graphql-relay-js
offset
and limit
computed values1// graphql resolver 2// ... 3return connectionToSqlQuery( 4 // this return totalCount for current select 5 await someOrmSqlModel.getTotalCount(), 6 paginationArgs, 7 // get computed values for sql pagination 8 ({ offset, limit }) => ( 9 // applying it to sql select for native sql pagination 10 someOrmSqlModel.getData({ offset, limit }) 11 ) 12)
1import { connectionToSqlQuery } from 'graphql-cursor-sql-helper' 2/* 3 _ _ _ _ 4 >(')____, >(')____, ... some code ... >(')____, >(') ___, 5 (` =~~/ (` =~~/ ... some code ... (` =~~/ (` =~~/ 6~^~~^~^`---'~^~^~^`---'~^~^~^`---'~^~^~^`---'~^~^~^`---'~^~^~ 7*/ 8const Admin = new GraphQLObjectType({ 9 name: 'Admin', 10 description: '...', 11 interfaces: [nodeInterface], 12 isTypeOf: obj => instanceof sqlModelAdmin, 13 fields: () => ({ 14 /* 15 _ _ _ _ 16 >(')____, >(')____, ... some code ... >(')____, >(') ___, 17 (` =~~/ (` =~~/ ... some code ... (` =~~/ (` =~~/ 18 ~^~~^~^`---'~^~^~^`---'~^~^~^`---'~^~^~^`---'~^~^~^`---'~^~^~ 19 */ 20 users: { 21 type: connectionDefinitions({ 22 name: 'User', 23 nodeType: UserType, 24 // adding connectionFields to type 25 // is necessary for quering totalCount in graphQl 26 connectionFields: { 27 totalCount: { type: new GraphQLNonNull(GraphQLInt) } 28 } 29 }).connectionType, 30 args: connectionArgs, 31 description: `...`, 32 resolve: async (parent, paginationArgs) => { 33 // call `graphql-sql-cursor-helper` function for calculating real OFFSET & LIMIT 34 return connectionToSqlQuery( 35 await someOrmSqlModel.getTotalCount(), // <- this 36 paginationArgs, 37 // get computed values for sql pagination 38 ({ offset, limit }) => ( 39 // applying it to sql select for native sql pagination 40 someOrmSqlModel.getUsers({ offset, limit }) 41 ) 42 ) 43 } 44 } 45 }) 46})
## Contributing
After cloning this repo, ensure dependencies are installed by running:
npm install
or yarn
Develop by
yarn run start
or npm run start
Test changes by
yarn run test
or npm run test
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
37 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More