@envelop/response-cache 6.1.1 → 6.1.2

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
@@ -490,7 +490,7 @@ import { execute, parse, subscribe, validate } from 'graphql'
490
490
  import { envelop } from '@envelop/core'
491
491
  import { ShouldCacheResultFunction, useResponseCache } from '@envelop/response-cache'
492
492
 
493
- export const defaultShouldCacheResult: ShouldCacheResultFunction = (params): Boolean => {
493
+ export const defaultShouldCacheResult: ShouldCacheResultFunction = (params): boolean => {
494
494
  // cache any query operation execution result
495
495
  // even if it includes errors
496
496
  return true
package/cjs/plugin.js CHANGED
@@ -130,7 +130,7 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
130
130
  [utils_1.MapperKind.COMPOSITE_TYPE]: type => {
131
131
  const cacheControlAnnotations = (0, utils_1.getDirective)(schema, type, 'cacheControl');
132
132
  cacheControlAnnotations?.forEach(cacheControl => {
133
- if (cacheControl.maxAge) {
133
+ if (cacheControl.maxAge != null) {
134
134
  ttlPerType[type.name] = cacheControl.maxAge * 1000;
135
135
  }
136
136
  if (cacheControl.scope) {
@@ -150,7 +150,7 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
150
150
  if (directive) {
151
151
  const cacheControlAnnotations = (0, utils_1.getDirective)(schema, fieldConfig, 'cacheControl');
152
152
  cacheControlAnnotations?.forEach(cacheControl => {
153
- if (cacheControl.maxAge) {
153
+ if (cacheControl.maxAge != null) {
154
154
  ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
155
155
  }
156
156
  if (cacheControl.scope) {
@@ -224,6 +224,10 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
224
224
  if (fieldData == null || (Array.isArray(fieldData) && fieldData.length === 0)) {
225
225
  const inferredTypes = typePerSchemaCoordinateMap.get(`${typename}.${fieldName}`);
226
226
  inferredTypes?.forEach(inferredType => {
227
+ if (inferredType in ttlPerType) {
228
+ const maybeTtl = ttlPerType[inferredType];
229
+ currentTtl = calculateTtl(maybeTtl, currentTtl);
230
+ }
227
231
  identifier.set(inferredType, { typename: inferredType });
228
232
  });
229
233
  }
package/esm/plugin.js CHANGED
@@ -123,7 +123,7 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
123
123
  [MapperKind.COMPOSITE_TYPE]: type => {
124
124
  const cacheControlAnnotations = getDirective(schema, type, 'cacheControl');
125
125
  cacheControlAnnotations?.forEach(cacheControl => {
126
- if (cacheControl.maxAge) {
126
+ if (cacheControl.maxAge != null) {
127
127
  ttlPerType[type.name] = cacheControl.maxAge * 1000;
128
128
  }
129
129
  if (cacheControl.scope) {
@@ -143,7 +143,7 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
143
143
  if (directive) {
144
144
  const cacheControlAnnotations = getDirective(schema, fieldConfig, 'cacheControl');
145
145
  cacheControlAnnotations?.forEach(cacheControl => {
146
- if (cacheControl.maxAge) {
146
+ if (cacheControl.maxAge != null) {
147
147
  ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
148
148
  }
149
149
  if (cacheControl.scope) {
@@ -217,6 +217,10 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
217
217
  if (fieldData == null || (Array.isArray(fieldData) && fieldData.length === 0)) {
218
218
  const inferredTypes = typePerSchemaCoordinateMap.get(`${typename}.${fieldName}`);
219
219
  inferredTypes?.forEach(inferredType => {
220
+ if (inferredType in ttlPerType) {
221
+ const maybeTtl = ttlPerType[inferredType];
222
+ currentTtl = calculateTtl(maybeTtl, currentTtl);
223
+ }
220
224
  identifier.set(inferredType, { typename: inferredType });
221
225
  });
222
226
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/response-cache",
3
- "version": "6.1.1",
3
+ "version": "6.1.2",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@envelop/core": "^5.0.0",
@@ -20,7 +20,7 @@ export type GetDocumentStringFunction = (executionArgs: ExecutionArgs) => string
20
20
  export type ShouldCacheResultFunction = (params: {
21
21
  cacheKey: string;
22
22
  result: ExecutionResult;
23
- }) => Boolean;
23
+ }) => boolean;
24
24
  export type UseResponseCacheParameter<PluginContext extends Record<string, any> = {}> = {
25
25
  cache?: Cache;
26
26
  /**
@@ -104,7 +104,7 @@ export type UseResponseCacheParameter<PluginContext extends Record<string, any>
104
104
  includeExtensionMetadata?: boolean;
105
105
  /**
106
106
  * Checks if the execution result should be cached or ignored. By default, any execution that
107
- * raises any error, unexpected ot EnvelopError or GraphQLError are ignored.
107
+ * raises any error is ignored.
108
108
  * Use this function to customize the behavior, such as caching results that have an EnvelopError.
109
109
  */
110
110
  shouldCacheResult?: ShouldCacheResultFunction;
@@ -20,7 +20,7 @@ export type GetDocumentStringFunction = (executionArgs: ExecutionArgs) => string
20
20
  export type ShouldCacheResultFunction = (params: {
21
21
  cacheKey: string;
22
22
  result: ExecutionResult;
23
- }) => Boolean;
23
+ }) => boolean;
24
24
  export type UseResponseCacheParameter<PluginContext extends Record<string, any> = {}> = {
25
25
  cache?: Cache;
26
26
  /**
@@ -104,7 +104,7 @@ export type UseResponseCacheParameter<PluginContext extends Record<string, any>
104
104
  includeExtensionMetadata?: boolean;
105
105
  /**
106
106
  * Checks if the execution result should be cached or ignored. By default, any execution that
107
- * raises any error, unexpected ot EnvelopError or GraphQLError are ignored.
107
+ * raises any error is ignored.
108
108
  * Use this function to customize the behavior, such as caching results that have an EnvelopError.
109
109
  */
110
110
  shouldCacheResult?: ShouldCacheResultFunction;