mercurius-cache
Advanced tools
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) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50411
1939