Gathering detailed insights and metrics for mongo-relay-connection
Gathering detailed insights and metrics for mongo-relay-connection
Gathering detailed insights and metrics for mongo-relay-connection
Gathering detailed insights and metrics for mongo-relay-connection
Assist building relay connection from mongoose.
npm install mongo-relay-connection
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
8 Stars
175 Commits
5 Forks
3 Watchers
18 Branches
2 Contributors
Updated on Mar 21, 2020
Latest Version
0.2.8
Package Id
mongo-relay-connection@0.2.8
Unpacked Size
259.72 kB
Size
87.05 kB
File Count
22
NPM Version
6.10.1
Node Version
11.15.0
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
2
24
1yarn add mongo-relay-connection graphql graphql-relay
graphql
and graphql-relay
are required as peer dependencies.
To assist building a Relay Connection type from a mongoose schema. It supports dynamic collection. The order could be based on a field that is not necessarily unique. And existing schema need not be changed at all.
It is based on the Relay pagination algorithm. But as including a value for both first and last is confusing, the last is ignored if both are given.
# | after | first | before | last | remarks | support |
---|---|---|---|---|---|---|
1 | returns all | ✓ | ||||
2 | ✓ | ✓ | ||||
3 | ✓ | ✓ | ||||
4 | ✓ | ✓ | ✓ | |||
5 | ✓ | ✓ | ||||
6 | ✓ | ✓ | same as #5 | ✗ | ||
7 | ✓ | ✓ | ✓ | |||
8 | ✓ | ✓ | ✓ | same as #7 | ✗ | |
9 | ✓ | ✓ | ||||
10 | ✓ | ✓ | ✓ | |||
11 | ✓ | ✓ | ✓ | |||
12 | ✓ | ✓ | ✓ | ✓ | ||
13 | ✓ | ✓ | ✓ | |||
14 | ✓ | ✓ | ✓ | same as #13 | ✗ | |
15 | ✓ | ✓ | ✓ | ✓ | ||
16 | ✓ | ✓ | ✓ | ✓ | same as #15 | ✗ |
Suppose you want to do cursor based pagination over a collection:
1// models/product.js 2 3import mongoose, { Schema } from 'mongoose' 4 5const ProductSchema = new Schema({ 6 name: String, 7 type: String, 8 price: Number 9}) 10 11export default mongoose.model('Product', ProductSchema)
First create a corresponding GraphQLObjectType:
1// types/product.js 2 3import { 4 GraphQLObjectType, 5 GraphQLID, 6 GraphQLString, 7 GraphQLInt 8} from 'graphql' 9 10const Product = new GraphQLObjectType({ 11 name: 'Product', 12 fields: { 13 id: { type: GraphQLID }, 14 name: { type: GraphQLString }, 15 type: { type: GraphQLString }, 16 price: { type: GraphQLInt } 17 } 18}) 19 20export default Product
Then create your query by defining the type, args, and resolve function. Here all the food product is selected and sorted by price descendingly:
1import { 2 GraphQLObjectType 3} from 'graphql' 4import { 5 mrType, 6 mrArgs, 7 mrResolve 8} from 'mongo-relay-connection' 9import Product from './types/product' 10import ProductModel from './models/product' 11 12const foodTypes = [ 13 "Bacon", 14 "Cheese", 15 "Chicken", 16 "Chips", 17 "Fish", 18 "Pizza", 19 "Salad", 20 "Sausages", 21 "Tuna" 22] 23 24const RootQuery = new GraphQLObjectType({ 25 name: 'RootQuery', 26 fields: { 27 allFoodProducts: { 28 type: mrType('FoodProduct', Product), 29 args: mrArgs, 30 resolve (parentValue, args) { 31 const query = { 32 type: { $in: foodTypes } 33 } 34 const opts = { 35 cursorField: 'price', 36 direction: -1 37 } 38 return mrResolve(args, ProductModel, query, opts) 39 } 40 } 41 } 42}) 43 44export default RootQuery
Boom, you're done! No third step. All the hard work of resolving is done for you.
It is based on sorting on a single given field (default is _id). If the field is not unique, it is compounded with _id as the secondary sort. So it could only be sorted in one given dimension.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/26 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 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
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
60 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