
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
@entria/graphql-mongoose-loader
Advanced tools
npm i @entria/graphql-mongoose-loader --save
yarn add @entria/graphql-mongoose-loader
Add batch to your GraphQL resolvers/loaders
Define a mongoose schema for your model
import mongoose from 'mongoose';
const Schema = new mongoose.Schema(
{
name: {
type: String,
},
email: {
type: String,
required: true,
index: true,
},
password: {
type: String,
hidden: true,
},
},
{
collection: 'User',
},
);
export default mongoose.model('User', Schema);
Create a Dataloader for it
import { mongooseLoader } from '@entria/graphql-mongoose-loader';
import UserModel from './User';
export const getLoader = () => new DataLoader(ids => mongooseLoader(UserModel, ids));
Create a connection from mongoose cursor
import { connectionFromMongoCursor } from '@entria/graphql-mongoose-loader';
export const loadUsers = async (context: GraphQLContext, args: ConnectionArguments) => {
const where = args.search
? {
name: {
$regex: new RegExp(`^${args.search}`, 'ig'),
},
}
: {};
const users = UserModel.find(where, { _id: 1 }).sort({
createdAt: -1,
});
return connectionFromMongoCursor({
cursor: users,
context,
args,
loader: load,
});
};
Create a connection from mongoose aggregate
import { connectionFromMongoAggregate } from '@entria/graphql-mongoose-loader';
export const loadUsersThatHaveGroup = async (context: GraphQLContext, args: ConnectionArguments) => {
const aggregate = GroupModel.aggregate([
{
$lookup: {
from: 'User',
localField: 'users',
foreignField: '_id',
as: 'users',
},
},
{
// remove empty groups
$match: { users: { $exists: true, $ne: [] } },
},
{
// promote each user to a new document
$unwind: '$users',
},
{
$sort: {
_id: 1,
},
},
{
$replaceRoot: { newRoot: '$users' },
},
]);
return connectionFromMongoAggregate({
aggregate,
context,
args,
loader: load,
});
};
FAQs
GraphQL Mongoose Loader helpers
We found that @entria/graphql-mongoose-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.