
Security News
OpenGrep Restores Fingerprinting in JSON and SARIF Outputs
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
@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
The npm package @entria/graphql-mongoose-loader receives a total of 849 weekly downloads. As such, @entria/graphql-mongoose-loader popularity was classified as not popular.
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
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
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.