@envelop/response-cache 4.0.0 → 4.0.2-alpha-20221014125414-4a8038f2

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/README.md CHANGED
@@ -38,13 +38,13 @@ When configuring the `useResponseCache`, you can choose the type of cache:
38
38
  The in-memory LRU cache is used by default.
39
39
 
40
40
  ```ts
41
- import { parse, validate, execute, subscribe } from 'graphql'
41
+ import { parse, validate, specifiedRules, execute, subscribe } from 'graphql'
42
42
  import { envelop, useEngine } from '@envelop/core'
43
43
  import { useResponseCache } from '@envelop/response-cache'
44
44
 
45
45
  const getEnveloped = envelop({
46
46
  plugins: [
47
- useEngine({ parse, validate, execute, subscribe }),
47
+ useEngine({ parse, validate, specifiedRules, execute, subscribe }),
48
48
  // ... other plugins ...
49
49
  useResponseCache({
50
50
  // use global cache for all operations
@@ -57,7 +57,7 @@ const getEnveloped = envelop({
57
57
  Or, you may create the in-memory LRU cache explicitly.
58
58
 
59
59
  ```ts
60
- import { parse, validate, execute, subscribe } from 'graphql'
60
+ import { parse, validate, specifiedRules, execute, subscribe } from 'graphql'
61
61
  import { envelop, useEngine } from '@envelop/core'
62
62
  import { useResponseCache, createInMemoryCache } from '@envelop/response-cache'
63
63
 
@@ -65,7 +65,7 @@ const cache = createInMemoryCache()
65
65
 
66
66
  const getEnveloped = envelop({
67
67
  plugins: [
68
- useEngine({ parse, validate, execute, subscribe }),
68
+ useEngine({ parse, validate, specifiedRules, execute, subscribe }),
69
69
  // ... other plugins ...
70
70
  useResponseCache({
71
71
  cache,
@@ -80,13 +80,13 @@ const getEnveloped = envelop({
80
80
  ### Cache based on session/user
81
81
 
82
82
  ```ts
83
- import { parse, validate, execute, subscribe } from 'graphql'
83
+ import { parse, validate, specifiedRules, execute, subscribe } from 'graphql'
84
84
  import { envelop, useEngine } from '@envelop/core'
85
85
  import { useResponseCache } from '@envelop/response-cache'
86
86
 
87
87
  const getEnveloped = envelop({
88
88
  plugins: [
89
- useEngine({ parse, validate, execute, subscribe }),
89
+ useEngine({ parse, validate, specifiedRules, execute, subscribe }),
90
90
  // ... other plugins ...
91
91
  useResponseCache({
92
92
  ttl: 2000,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/response-cache",
3
- "version": "4.0.0",
3
+ "version": "4.0.2-alpha-20221014125414-4a8038f2",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "^3.0.0",
6
+ "@envelop/core": "3.0.2-alpha-20221014125414-4a8038f2",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
@@ -1,4 +1,4 @@
1
1
  import { ExecutionArgs } from 'graphql';
2
2
  import { Plugin } from '@envelop/core';
3
- export declare function useCacheDocumentString(): Plugin;
3
+ export declare function useCacheDocumentString<PluginContext extends Record<string, any> = {}>(): Plugin<PluginContext>;
4
4
  export declare function defaultGetDocumentString(executionArgs: ExecutionArgs): string;
@@ -1,4 +1,4 @@
1
1
  import { ExecutionArgs } from 'graphql';
2
2
  import { Plugin } from '@envelop/core';
3
- export declare function useCacheDocumentString(): Plugin;
3
+ export declare function useCacheDocumentString<PluginContext extends Record<string, any> = {}>(): Plugin<PluginContext>;
4
4
  export declare function defaultGetDocumentString(executionArgs: ExecutionArgs): string;
@@ -18,7 +18,7 @@ export declare type GetDocumentStringFunction = (executionArgs: ExecutionArgs) =
18
18
  export declare type ShouldCacheResultFunction = (params: {
19
19
  result: ExecutionResult;
20
20
  }) => Boolean;
21
- export declare type UseResponseCacheParameter<C = any> = {
21
+ export declare type UseResponseCacheParameter<PluginContext extends Record<string, any> = {}> = {
22
22
  cache?: Cache;
23
23
  /**
24
24
  * Maximum age in ms. Defaults to `Infinity`. Set it to 0 for disabling the global TTL.
@@ -60,12 +60,12 @@ export declare type UseResponseCacheParameter<C = any> = {
60
60
  * });
61
61
  * ```
62
62
  */
63
- session(context: C): string | undefined | null;
63
+ session(context: PluginContext): string | undefined | null;
64
64
  /**
65
65
  * Specify whether the cache should be used based on the context.
66
66
  * By default any request uses the cache.
67
67
  */
68
- enabled?(context: C): boolean;
68
+ enabled?(context: PluginContext): boolean;
69
69
  /**
70
70
  * Skip caching of following the types.
71
71
  */
@@ -119,4 +119,4 @@ export declare const defaultBuildResponseCacheKey: BuildResponseCacheKeyFunction
119
119
  * By default, results with errors (unexpected, EnvelopError, or GraphQLError) are not cached.
120
120
  */
121
121
  export declare const defaultShouldCacheResult: ShouldCacheResultFunction;
122
- export declare function useResponseCache({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, includeExtensionMetadata, }: UseResponseCacheParameter): Plugin;
122
+ export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, includeExtensionMetadata, }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;
@@ -18,7 +18,7 @@ export declare type GetDocumentStringFunction = (executionArgs: ExecutionArgs) =
18
18
  export declare type ShouldCacheResultFunction = (params: {
19
19
  result: ExecutionResult;
20
20
  }) => Boolean;
21
- export declare type UseResponseCacheParameter<C = any> = {
21
+ export declare type UseResponseCacheParameter<PluginContext extends Record<string, any> = {}> = {
22
22
  cache?: Cache;
23
23
  /**
24
24
  * Maximum age in ms. Defaults to `Infinity`. Set it to 0 for disabling the global TTL.
@@ -60,12 +60,12 @@ export declare type UseResponseCacheParameter<C = any> = {
60
60
  * });
61
61
  * ```
62
62
  */
63
- session(context: C): string | undefined | null;
63
+ session(context: PluginContext): string | undefined | null;
64
64
  /**
65
65
  * Specify whether the cache should be used based on the context.
66
66
  * By default any request uses the cache.
67
67
  */
68
- enabled?(context: C): boolean;
68
+ enabled?(context: PluginContext): boolean;
69
69
  /**
70
70
  * Skip caching of following the types.
71
71
  */
@@ -119,4 +119,4 @@ export declare const defaultBuildResponseCacheKey: BuildResponseCacheKeyFunction
119
119
  * By default, results with errors (unexpected, EnvelopError, or GraphQLError) are not cached.
120
120
  */
121
121
  export declare const defaultShouldCacheResult: ShouldCacheResultFunction;
122
- export declare function useResponseCache({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, includeExtensionMetadata, }: UseResponseCacheParameter): Plugin;
122
+ export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, includeExtensionMetadata, }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;