Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mercurius-cache

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mercurius-cache - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

11

index.js

@@ -126,5 +126,10 @@ 'use strict'

return async function (self, arg, ctx, info) {
if ((skip && await skip(self, arg, ctx, info)) ||
(policy && policy.skip && await policy.skip(self, arg, ctx, info))) {
onSkip()
const isMutation =
info.operation && info.operation.operation === 'mutation'
if (
(skip && (await skip(self, arg, ctx, info))) ||
isMutation ||
(policy && policy.skip && (await policy.skip(self, arg, ctx, info)))
) {
if (!isMutation) onSkip()
return originalFieldResolver(self, arg, ctx, info)

@@ -131,0 +136,0 @@ }

{
"name": "mercurius-cache",
"version": "0.8.0",
"version": "0.9.0",
"description": "Cache the results of your GraphQL resolvers, for Mercurius",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -588,1 +588,98 @@ 'use strict'

})
test('skip the cache if operation is Mutation', async ({ equal, same, teardown }) => {
const app = fastify()
teardown(app.close.bind(app))
let skipCount = 0
let hitCount = 0
const schema = `
type Mutation {
add(a: Int, b: Int): Int
}
type Query {
hello: String
}
`
const resolvers = {
Mutation: {
add: (_, { a, b }) => a + b
}
}
app.register(mercurius, {
schema,
resolvers
})
app.register(cache, {
all: true,
onSkip (type, name) {
equal(type, 'Mutation')
equal(name, 'add')
skipCount++
},
onHit (type, name) {
equal(type, 'Mutation')
equal(name, 'add')
hitCount++
}
})
const query = 'mutation { add(a: 11 b: 19) }'
{
const res = await app.inject({
method: 'POST',
url: '/graphql',
body: {
query
}
})
equal(res.statusCode, 200)
same(res.json(), {
data: {
add: 30
}
})
}
{
const res = await app.inject({
method: 'POST',
url: '/graphql',
body: {
query
}
})
equal(res.statusCode, 200)
same(res.json(), {
data: {
add: 30
}
})
}
{
const res = await app.inject({
method: 'POST',
url: '/graphql',
body: {
query
}
})
equal(res.statusCode, 200)
same(res.json(), {
data: {
add: 30
}
})
}
equal(skipCount, 0)
equal(hitCount, 0)
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc