@envelop/response-cache 5.2.0 → 5.3.0-alpha-20230908093945-02e7e8ad

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/plugin.js CHANGED
@@ -12,7 +12,7 @@ const in_memory_cache_js_1 = require("./in-memory-cache.js");
12
12
  * Default function used for building the response cache key.
13
13
  * It is exported here for advanced use-cases. E.g. if you want to short circuit and serve responses from the cache on a global level in order to completely by-pass the GraphQL flow.
14
14
  */
15
- const defaultBuildResponseCacheKey = params => (0, hash_sha256_js_1.hashSHA256)([
15
+ const defaultBuildResponseCacheKey = (params) => (0, hash_sha256_js_1.hashSHA256)([
16
16
  params.documentString,
17
17
  params.operationName ?? '',
18
18
  (0, fast_json_stable_stringify_1.default)(params.variableValues ?? {}),
@@ -219,6 +219,7 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
219
219
  variableValues: onExecuteParams.args.variableValues,
220
220
  operationName: onExecuteParams.args.operationName,
221
221
  sessionId,
222
+ context: onExecuteParams.args.contextValue,
222
223
  });
223
224
  if ((enabled?.(onExecuteParams.args.contextValue) ?? true) === true) {
224
225
  const cachedResponse = (await cache.get(cacheKey));
package/esm/plugin.js CHANGED
@@ -8,7 +8,7 @@ import { createInMemoryCache } from './in-memory-cache.js';
8
8
  * Default function used for building the response cache key.
9
9
  * It is exported here for advanced use-cases. E.g. if you want to short circuit and serve responses from the cache on a global level in order to completely by-pass the GraphQL flow.
10
10
  */
11
- export const defaultBuildResponseCacheKey = params => hashSHA256([
11
+ export const defaultBuildResponseCacheKey = (params) => hashSHA256([
12
12
  params.documentString,
13
13
  params.operationName ?? '',
14
14
  jsonStableStringify(params.variableValues ?? {}),
@@ -212,6 +212,7 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
212
212
  variableValues: onExecuteParams.args.variableValues,
213
213
  operationName: onExecuteParams.args.operationName,
214
214
  sessionId,
215
+ context: onExecuteParams.args.contextValue,
215
216
  });
216
217
  if ((enabled?.(onExecuteParams.args.contextValue) ?? true) === true) {
217
218
  const cachedResponse = (await cache.get(cacheKey));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/response-cache",
3
- "version": "5.2.0",
3
+ "version": "5.3.0-alpha-20230908093945-02e7e8ad",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@envelop/core": "^4.0.1",
@@ -13,6 +13,8 @@ export type BuildResponseCacheKeyFunction = (params: {
13
13
  operationName?: Maybe<string>;
14
14
  /** optional sessionId for make unique cache keys based on the session. */
15
15
  sessionId: Maybe<string>;
16
+ /** GraphQL Context */
17
+ context: ExecutionArgs['contextValue'];
16
18
  }) => Promise<string>;
17
19
  export type GetDocumentStringFunction = (executionArgs: ExecutionArgs) => string;
18
20
  export type ShouldCacheResultFunction = (params: {
@@ -111,7 +113,12 @@ export type UseResponseCacheParameter<PluginContext extends Record<string, any>
111
113
  * Default function used for building the response cache key.
112
114
  * It is exported here for advanced use-cases. E.g. if you want to short circuit and serve responses from the cache on a global level in order to completely by-pass the GraphQL flow.
113
115
  */
114
- export declare const defaultBuildResponseCacheKey: BuildResponseCacheKeyFunction;
116
+ export declare const defaultBuildResponseCacheKey: (params: {
117
+ documentString: string;
118
+ variableValues: ExecutionArgs['variableValues'];
119
+ operationName?: Maybe<string>;
120
+ sessionId: Maybe<string>;
121
+ }) => Promise<string>;
115
122
  /**
116
123
  * Default function used to check if the result should be cached.
117
124
  *
@@ -13,6 +13,8 @@ export type BuildResponseCacheKeyFunction = (params: {
13
13
  operationName?: Maybe<string>;
14
14
  /** optional sessionId for make unique cache keys based on the session. */
15
15
  sessionId: Maybe<string>;
16
+ /** GraphQL Context */
17
+ context: ExecutionArgs['contextValue'];
16
18
  }) => Promise<string>;
17
19
  export type GetDocumentStringFunction = (executionArgs: ExecutionArgs) => string;
18
20
  export type ShouldCacheResultFunction = (params: {
@@ -111,7 +113,12 @@ export type UseResponseCacheParameter<PluginContext extends Record<string, any>
111
113
  * Default function used for building the response cache key.
112
114
  * It is exported here for advanced use-cases. E.g. if you want to short circuit and serve responses from the cache on a global level in order to completely by-pass the GraphQL flow.
113
115
  */
114
- export declare const defaultBuildResponseCacheKey: BuildResponseCacheKeyFunction;
116
+ export declare const defaultBuildResponseCacheKey: (params: {
117
+ documentString: string;
118
+ variableValues: ExecutionArgs['variableValues'];
119
+ operationName?: Maybe<string>;
120
+ sessionId: Maybe<string>;
121
+ }) => Promise<string>;
115
122
  /**
116
123
  * Default function used to check if the result should be cached.
117
124
  *