
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@northernv/dataloader
Advanced tools
npm install -S @northernv/dataloader;
yarn add @northernv/dataloader;
In your models, that are Javascript classes, include a static function called loaders
that returns an object of dataloaders
class Property {
static loaders (DataLoader, { db }) {
const manyPropertyById = new DataLoader(propertyIds => {
return db('property').whereIn('id', propertyIds)
.then(rows => propertyIds.map(id => rows.filter(x => x.id === id)))
})
const manyPropertyByAssociationId = new DataLoader(associationIds => {
return db('property').whereIn('property.assocation_id', associationIds)
.then(rows => associationIds.map(id => rows.filter(x => x.assocationId === id)))
})
const onePropertyById = new DataLoader(propertyIds => {
return db('property').whereIn('id', propertyIds)
.then(rows => propertyIds.map(id => rows.find(x => x.id === id)))
})
return { manyPropertyById, manyPropertyByAssociationId, onePropertyById }
}
}
Each loader should follow the patter one<ClassName>By<PropertyName>
or many<ClassName>By<PropertyName>
In your bootstrapping file
const loader = dataloaders('models', { db })
const server = new ApolloServer({
schema,
// Create new Dataloaders for each request
context: ({ req, res }) => new Context({ req, res, db, channel, loaders: loader() }),
formatError: (error) => {
Sentry.captureException(error)
return { ...error, code: get(error, 'originalError.constructor.name', 'Unknown') }
},
})
or you can delay adding the db
option until runtime
// Notice here we do not pass in the run time option `db`
const loader = dataloaders('models')
const server = new ApolloServer({
schema,
// Create new Dataloaders for each request
// Instead we pass in the runtime option `db` here on init
context: ({ req, res }) => new Context({ req, res, db, channel, loaders: loader({ db }) }),
formatError: (error) => {
Sentry.captureException(error)
return { ...error, code: get(error, 'originalError.constructor.name', 'Unknown') }
},
})
See how we pass in the model
directory that is relative to the project root and our options. The options will be passed to each of the loaders
functions
filter
, while One loaders user find
FAQs
A framework for dataloaders in models
The npm package @northernv/dataloader receives a total of 5 weekly downloads. As such, @northernv/dataloader popularity was classified as not popular.
We found that @northernv/dataloader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.