@graphql-yoga/plugin-response-cache 3.1.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -48,20 +48,24 @@ function useResponseCache(options) {
48
48
  session: sessionFactoryForEnvelop,
49
49
  buildResponseCacheKey: cacheKeyFactoryForEnvelop,
50
50
  shouldCacheResult({ cacheKey, result }) {
51
- const shouldCached = options.shouldCacheResult
52
- ? options.shouldCacheResult({ cacheKey, result })
53
- : !result.errors?.length;
54
- if (shouldCached) {
51
+ let shouldCache;
52
+ if (options.shouldCacheResult) {
53
+ shouldCache = options.shouldCacheResult({ cacheKey, result });
54
+ }
55
+ else {
56
+ shouldCache = !result.errors?.length;
57
+ if (!shouldCache) {
58
+ logger.debug('[useResponseCache] Decided not to cache the response because it contains errors');
59
+ }
60
+ }
61
+ if (shouldCache) {
55
62
  const extensions = (result.extensions ||= {});
56
63
  const httpExtensions = (extensions.http ||= {});
57
64
  const headers = (httpExtensions.headers ||= {});
58
65
  headers['ETag'] = cacheKey;
59
66
  headers['Last-Modified'] = new Date().toUTCString();
60
67
  }
61
- else {
62
- logger.warn('[useResponseCache] Failed to cache due to errors');
63
- }
64
- return shouldCached;
68
+ return shouldCache;
65
69
  },
66
70
  }));
67
71
  },
package/esm/index.js CHANGED
@@ -43,20 +43,24 @@ export function useResponseCache(options) {
43
43
  session: sessionFactoryForEnvelop,
44
44
  buildResponseCacheKey: cacheKeyFactoryForEnvelop,
45
45
  shouldCacheResult({ cacheKey, result }) {
46
- const shouldCached = options.shouldCacheResult
47
- ? options.shouldCacheResult({ cacheKey, result })
48
- : !result.errors?.length;
49
- if (shouldCached) {
46
+ let shouldCache;
47
+ if (options.shouldCacheResult) {
48
+ shouldCache = options.shouldCacheResult({ cacheKey, result });
49
+ }
50
+ else {
51
+ shouldCache = !result.errors?.length;
52
+ if (!shouldCache) {
53
+ logger.debug('[useResponseCache] Decided not to cache the response because it contains errors');
54
+ }
55
+ }
56
+ if (shouldCache) {
50
57
  const extensions = (result.extensions ||= {});
51
58
  const httpExtensions = (extensions.http ||= {});
52
59
  const headers = (httpExtensions.headers ||= {});
53
60
  headers['ETag'] = cacheKey;
54
61
  headers['Last-Modified'] = new Date().toUTCString();
55
62
  }
56
- else {
57
- logger.warn('[useResponseCache] Failed to cache due to errors');
58
- }
59
- return shouldCached;
63
+ return shouldCache;
60
64
  },
61
65
  }));
62
66
  },
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-yoga/plugin-response-cache",
3
- "version": "3.1.2",
3
+ "version": "3.2.0",
4
4
  "description": "",
5
5
  "peerDependencies": {
6
6
  "graphql": "^15.2.0 || ^16.0.0",
7
- "graphql-yoga": "^5.0.2"
7
+ "graphql-yoga": "^5.1.0"
8
8
  },
9
9
  "dependencies": {
10
- "@envelop/response-cache": "^6.1.0"
10
+ "@envelop/response-cache": "^6.1.2"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",