Gathering detailed insights and metrics for @lotosbin/graphql-relay-connection
Gathering detailed insights and metrics for @lotosbin/graphql-relay-connection
Gathering detailed insights and metrics for @lotosbin/graphql-relay-connection
Gathering detailed insights and metrics for @lotosbin/graphql-relay-connection
A GraphQL Relay connection with cursor based on any comparator. Can be used with ObjectId for MongoDB.
npm install @lotosbin/graphql-relay-connection
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
20 Stars
19 Commits
3 Forks
4 Watchers
2 Branches
1 Contributors
Updated on Feb 15, 2022
Latest Version
0.0.4
Package Id
@lotosbin/graphql-relay-connection@0.0.4
Size
42.97 kB
NPM Version
5.5.1
Node Version
8.9.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
A GraphQL Relay connection with custom cursor functions. Can be used for MongoDB, Mongoose, plain objects, scalars, or any data formats.
npm install --save graphql-relay-connection
mongooseConnection
is predefined for you.
For other usage, scroll down to Custom connection
section below.
1import { 2 connectionDefinitions, 3 connectionArgs, 4} from 'graphql-relay'; 5 6import {mongooseConnection} from 'graphql-relay-connection'; 7 8const { 9 connectionFromPromisedArray, 10 cursorToDocument, 11} = mongooseConnection; 12 13const UserType = new GraphQLObjectType({ 14 name: 'User', 15 fields: () => ({ 16 friends: { 17 type: UserConnection, 18 args: connectionArgs, 19 resolve: (user, args) => { 20 args.first = args.first || 10; 21 const doc = cursorToDocument(args.after); 22 const friends = User.find({ 23 isFriendWith: user._id, 24 _id: {$gt: doc && doc._id}, 25 }) 26 .limit(args.first + 1) // add +1 for hasNextPage 27 .exec() 28 return connectionFromPromisedArray(friends, args); 29 }, 30 }, 31 }), 32}); 33 34const { 35 connectionType: UserConnection, 36} = connectionDefinitions({ 37 nodeType: UserType, 38});
Simply provide { comparableToCursor, cursorToComparable, comparator }
to defineConnection
.
1import defineConnection from 'graphql-relay-connection'; 2import { 3 base64, 4 unbase64, 5} from './util'; 6 7const PREFIX = 'number:'; 8 9// Given a comparable value, return a string cursor. 10function numberToCursor(num) { 11 return base64(PREFIX + num); 12} 13 14// Given a string cursor, 15// return a comparable value for the comparator function. 16function cursorToNumber(cursor) { 17 const num = parseInt(unbase64(cursor).substring(PREFIX.length), 10); 18 return isNaN(num) ? null : num; 19} 20 21// Sort function for array.sort(). 22// Given two values, return an interger. 23function compareNumbers(num1, num2) { 24 return num1 - num2; 25} 26 27const { 28 connectionFromArray, 29 connectionFromPromisedArray, 30} = defineConnection({ 31 comparableToCursor: numberToCursor, 32 cursorToComparable: cursorToNumber, 33 comparator: compareNumbers, 34});
1import type { 2 ConnectionCursor, 3} from './connectionTypes'; 4import defineConnection from './defineConnection'; 5import { 6 base64, 7 unbase64, 8 startsWith, 9} from './util'; 10 11 12export type ID = string; 13 14export type Document = { 15 id: ID, 16}; 17 18 19const PREFIX = 'mongoose:'; 20 21 22function documentToCursor(doc: Document): ConnectionCursor { 23 return base64(PREFIX + doc.id); 24} 25 26 27function cursorToDocument(cursor: ConnectionCursor): ?Document { 28 const unbased = unbase64(cursor); 29 if (startsWith(unbased, PREFIX)) { 30 const id = unbased.substring(PREFIX.length); 31 if (id) return {id}; 32 } 33 return null; 34} 35 36 37function compareDocuments(doc1: Document, doc2: Document): number { 38 if (doc1.id < doc2.id) { 39 return -1; 40 } 41 if (doc1.id > doc2.id) { 42 return 1; 43 } 44 return 0; 45} 46 47 48const { 49 connectionFromArray, 50 connectionFromPromisedArray, 51} = defineConnection({ 52 comparableToCursor: documentToCursor, 53 cursorToComparable: cursorToDocument, 54 comparator: compareDocuments, 55}); 56 57 58export { 59 compareDocuments, 60 connectionFromArray, 61 connectionFromPromisedArray, 62 cursorToDocument, 63 documentToCursor, 64};
The MIT License (MIT)
Copyright (c) 2016 Joon Ho Cho
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
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