mercurius-cache
Advanced tools
Comparing version 5.0.0 to 6.0.0
@@ -1,2 +0,1 @@ | ||
'use strict' | ||
@@ -3,0 +2,0 @@ |
{ | ||
"name": "mercurius-cache", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Cache the results of your GraphQL resolvers, for Mercurius", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"test": "standard | snazzy && tap test/*test.js && tsd", | ||
"redis": "docker run -p 6379:6379 --rm redis:5", | ||
"redis": "docker run -p 6379:6379 --rm redis:7", | ||
"lint:fix": "standard --fix" | ||
@@ -30,20 +30,20 @@ }, | ||
"@fastify/pre-commit": "^2.0.2", | ||
"@sinonjs/fake-timers": "^10.0.2", | ||
"autocannon": "^7.10.0", | ||
"concurrently": "^8.0.1", | ||
"fastify": "^4.11.0", | ||
"graphql": "^16.6.0", | ||
"@sinonjs/fake-timers": "^11.1.0", | ||
"autocannon": "^7.12.0", | ||
"concurrently": "^8.2.1", | ||
"fastify": "^4.23.2", | ||
"graphql": "^16.8.1", | ||
"graphql-type-json": "^0.3.2", | ||
"ioredis": "^5.2.5", | ||
"mercurius": "^13.0.0", | ||
"ioredis": "^5.3.2", | ||
"mercurius": "^13.1.0", | ||
"snazzy": "^9.0.0", | ||
"split2": "^4.1.0", | ||
"standard": "^17.0.0", | ||
"split2": "^4.2.0", | ||
"standard": "^17.1.0", | ||
"tap": "^16.3.4", | ||
"tsd": "^0.28.0", | ||
"typescript": "^5.0.2", | ||
"tsd": "^0.29.0", | ||
"typescript": "^5.2.2", | ||
"wait-on": "^7.0.1", | ||
"ws": "^8.12.0", | ||
"ws": "^8.14.2", | ||
"@mercuriusjs/federation": "^2.0.0", | ||
"@mercuriusjs/gateway": "^1.0.0" | ||
"@mercuriusjs/gateway": "^2.0.0" | ||
}, | ||
@@ -54,6 +54,6 @@ "tsd": { | ||
"dependencies": { | ||
"async-cache-dedupe": "^1.8.0", | ||
"fastify-plugin": "^4.5.0" | ||
"async-cache-dedupe": "^2.0.0", | ||
"fastify-plugin": "^4.5.1" | ||
}, | ||
"precommit": "test" | ||
} |
@@ -82,3 +82,3 @@ # mercurius-cache | ||
...js | ||
```js | ||
ttl: (result) => !!result.importantProp ? 10 : 0 | ||
@@ -217,3 +217,3 @@ ``` | ||
countries: { | ||
ttl: 1440, // Query "countries" will be cached for 1 day | ||
ttl: 86400, // Query "countries" will be cached for 1 day | ||
storage: { type: 'memory' } | ||
@@ -727,5 +727,53 @@ } | ||
## More info about how this plugin works | ||
This plugin caches the result of the resolver, but if the resolver returns a type incompatible with the schema return type, the plugin will cache the invalid return value. When you call the resolver again, the plugin will return the cached value, thereby caching the validation error. | ||
This issue may be exacerbated in a federation setup when you don't have full control over the implementation of federated schema and resolvers. | ||
Here you can find an example of the problem. | ||
```js | ||
'use strict' | ||
const fastify = require('fastify') | ||
const mercurius = require('mercurius') | ||
const cache = require('mercurius-cache') | ||
const app = fastify({ logger: true }) | ||
const schema = ` | ||
type Query { | ||
getNumber: Int | ||
} | ||
` | ||
const resolvers = { | ||
Query: { | ||
async getNumber(_, __, { reply }) { | ||
return "hello"; | ||
} | ||
} | ||
} | ||
app.register(mercurius, { | ||
schema, | ||
resolvers | ||
}) | ||
app.register(cache, { | ||
ttl: 10, | ||
policy: { | ||
Query: { | ||
getNumber: true | ||
} | ||
} | ||
}) | ||
``` | ||
If you come across this problem, you will first need to fix your code. Then you have two options: | ||
1. If you are you using an **in-memory** cache, it will be cleared at the next start of the application, so the impact of this issue will be limited | ||
2. If you are you using the **Redis** cache, you will need to manually invalidate the cache in Redis or wait for the TTL to expire | ||
## License | ||
MIT |
Sorry, the diff of this file is not supported yet
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
195614
777
+ Addedasync-cache-dedupe@2.2.0(transitive)
- Removedasync-cache-dedupe@1.12.0(transitive)
Updatedasync-cache-dedupe@^2.0.0
Updatedfastify-plugin@^4.5.1