Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
mercurius-cache
Advanced tools
Adds an in-process caching layer to Mercurius. Federation is fully supported.
Based on preliminary testing, it is possible to achieve a significant throughput improvement at the expense of the freshness of the data. Setting the ttl accordingly is of critical importance.
Under the covers it uses async-cache-dedupe
which will also deduplicate the calls.
npm i fastify mercurius mercurius-cache
'use strict'
const fastify = require('fastify')
const mercurius = require('mercurius')
const cache = require('.')
const app = fastify({ logger: true })
const schema = `
type Query {
add(x: Int, y: Int): Int
hello: String
}
`
const resolvers = {
Query: {
async add (_, { x, y }, { reply }) {
reply.log.info('add called')
for (let i = 0; i < 10000000; i++) {}
return x + y
}
}
}
app.register(mercurius, {
schema,
resolvers
})
app.register(cache, {
// all: true, // install the cache in all resolvers
// ttl: 10, // cache deta in process for ten seconds, default 0
remoteCache: {
// The remote cache is useful as a larger cache
async get (key) {
return ... // fetch a key from Redis
},
async set (key, value) {
// set the value in Redis
}
},
onHit (type, fieldName) {
// Called when a cached value is returned
},
onMiss (type, fieldName) {
// Called when there is no value in the cache
// It is not called if a resolver is skipped
},
// Useful to skip the cache for authenticated users or in some other condition
skip (self, arg, ctx, info) {
if (ctx.reply.request.headers.authorization) {
return true
}
return false
}
policy: {
Query: {
add: true
}
}
})
app.listen(3000)
// Use the following to test
// curl -X POST -H 'content-type: application/json' -d '{ "query": "{ add(x: 2, y: 2) }" }' localhost:3000/graphql
MIT
FAQs
Cache the results of your GraphQL resolvers, for Mercurius
The npm package mercurius-cache receives a total of 1,134 weekly downloads. As such, mercurius-cache popularity was classified as popular.
We found that mercurius-cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.