@envelop/response-cache 9.1.1 → 9.3.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/LICENSE CHANGED
@@ -1,6 +1,8 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dotan Simha
3
+ Copyright (c) 2018-2020 Graphcool
4
+ Copyright (c) 2020-2021 Prisma
5
+ Copyright (c) 2021- The Guild
4
6
 
5
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
8
  of this software and associated documentation files (the "Software"), to deal
@@ -8,8 +8,8 @@ function hashSHA256(text) {
8
8
  return (0, promise_helpers_1.handleMaybePromise)(() => fetch_1.crypto.subtle.digest({ name: 'SHA-256' }, inputUint8Array), arrayBuf => {
9
9
  const outputUint8Array = new Uint8Array(arrayBuf);
10
10
  let hash = '';
11
- for (let i = 0, l = outputUint8Array.length; i < l; i++) {
12
- const hex = outputUint8Array[i].toString(16);
11
+ for (const hexNum of outputUint8Array) {
12
+ const hex = hexNum.toString(16);
13
13
  hash += '00'.slice(0, Math.max(0, 2 - hex.length)) + hex;
14
14
  }
15
15
  return hash;
@@ -8,7 +8,7 @@ const createInMemoryCache = (params) => {
8
8
  max: params?.max ?? 1000,
9
9
  allowStale: false,
10
10
  noDisposeOnSet: true,
11
- dispose(responseId) {
11
+ dispose(_value, responseId) {
12
12
  purgeResponse(responseId, false);
13
13
  },
14
14
  });
@@ -19,8 +19,13 @@ const createInMemoryCache = (params) => {
19
19
  // get entities related to the response
20
20
  if (entityIds !== undefined) {
21
21
  for (const entityId of entityIds) {
22
- // remove the response mapping from the entity
23
- entityToResponseIds.get(entityId)?.delete(responseId);
22
+ const responseIds = entityToResponseIds.get(entityId);
23
+ if (responseIds) {
24
+ responseIds.delete(responseId);
25
+ if (responseIds.size === 0) {
26
+ entityToResponseIds.delete(entityId);
27
+ }
28
+ }
24
29
  }
25
30
  // remove all the entity mappings from the response
26
31
  responseIdToEntityIds.delete(responseId);
@@ -72,7 +77,7 @@ const createInMemoryCache = (params) => {
72
77
  },
73
78
  invalidate(entitiesToRemove) {
74
79
  for (const { typename, id } of entitiesToRemove) {
75
- purgeEntity(id != null ? buildEntityId(typename, id) : typename);
80
+ purgeEntity(id == null ? typename : buildEntityId(typename, id));
76
81
  }
77
82
  },
78
83
  };
package/cjs/plugin.js CHANGED
@@ -96,10 +96,9 @@ const getDocumentWithMetadataAndTTL = (0, utils_1.memoize4)(function addTypeName
96
96
  };
97
97
  return [(0, graphql_1.visit)(document, (0, graphql_1.visitWithTypeInfo)(typeInfo, visitor)), ttl];
98
98
  });
99
- function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache)(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = exports.defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = exports.defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process !== 'undefined'
100
- ? // eslint-disable-next-line dot-notation
101
- process.env['NODE_ENV'] === 'development' || !!process.env['DEBUG']
102
- : false, }) {
99
+ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache)(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = exports.defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = exports.defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process === 'undefined'
100
+ ? false
101
+ : process.env['NODE_ENV'] === 'development' || !!process.env['DEBUG'], }) {
103
102
  const cacheFactory = typeof cache === 'function' ? (0, utils_1.memoize1)(cache) : () => cache;
104
103
  const ignoredTypesMap = new Set(ignoredTypes);
105
104
  const typePerSchemaCoordinateMap = new Map();
@@ -136,14 +135,15 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
136
135
  ...(directive && {
137
136
  [utils_1.MapperKind.COMPOSITE_TYPE]: type => {
138
137
  const cacheControlAnnotations = (0, utils_1.getDirective)(schema, type, 'cacheControl');
139
- cacheControlAnnotations?.forEach(cacheControl => {
140
- if (cacheControl.maxAge != null) {
141
- ttlPerSchemaCoordinate[type.name] = cacheControl.maxAge * 1000;
138
+ if (cacheControlAnnotations)
139
+ for (const cacheControl of cacheControlAnnotations) {
140
+ if (cacheControl.maxAge != null) {
141
+ ttlPerSchemaCoordinate[type.name] = cacheControl.maxAge * 1000;
142
+ }
143
+ if (cacheControl.scope) {
144
+ scopePerSchemaCoordinate[type.name] = cacheControl.scope;
145
+ }
142
146
  }
143
- if (cacheControl.scope) {
144
- scopePerSchemaCoordinate[type.name] = cacheControl.scope;
145
- }
146
- });
147
147
  return type;
148
148
  },
149
149
  }),
@@ -156,14 +156,15 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
156
156
  }
157
157
  if (directive) {
158
158
  const cacheControlAnnotations = (0, utils_1.getDirective)(schema, fieldConfig, 'cacheControl');
159
- cacheControlAnnotations?.forEach(cacheControl => {
160
- if (cacheControl.maxAge != null) {
161
- ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
159
+ if (cacheControlAnnotations)
160
+ for (const cacheControl of cacheControlAnnotations) {
161
+ if (cacheControl.maxAge != null) {
162
+ ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
163
+ }
164
+ if (cacheControl.scope) {
165
+ scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
166
+ }
162
167
  }
163
- if (cacheControl.scope) {
164
- scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
165
- }
166
- });
167
168
  }
168
169
  return fieldConfig;
169
170
  },
@@ -174,7 +175,6 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
174
175
  return;
175
176
  }
176
177
  const identifier = new Map();
177
- const types = new Set();
178
178
  let currentTtl;
179
179
  let skip = false;
180
180
  const sessionId = session(onExecuteParams.args.contextValue);
@@ -210,7 +210,6 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
210
210
  entity.id = data[idField];
211
211
  }
212
212
  }
213
- types.add(entity.typename);
214
213
  if (entity.typename in ttlPerSchemaCoordinate) {
215
214
  const maybeTtl = ttlPerSchemaCoordinate[entity.typename];
216
215
  currentTtl = calculateTtl(maybeTtl, currentTtl);
@@ -222,13 +221,14 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
222
221
  const fieldData = data[fieldName];
223
222
  if (fieldData == null || (Array.isArray(fieldData) && fieldData.length === 0)) {
224
223
  const inferredTypes = typePerSchemaCoordinateMap.get(`${entity.typename}.${fieldName}`);
225
- inferredTypes?.forEach(inferredType => {
226
- if (inferredType in ttlPerSchemaCoordinate) {
227
- const maybeTtl = ttlPerSchemaCoordinate[inferredType];
228
- currentTtl = calculateTtl(maybeTtl, currentTtl);
224
+ if (inferredTypes)
225
+ for (const inferredType of inferredTypes) {
226
+ if (inferredType in ttlPerSchemaCoordinate) {
227
+ const maybeTtl = ttlPerSchemaCoordinate[inferredType];
228
+ currentTtl = calculateTtl(maybeTtl, currentTtl);
229
+ }
230
+ identifier.set(inferredType, { typename: inferredType });
229
231
  }
230
- identifier.set(inferredType, { typename: inferredType });
231
- });
232
232
  }
233
233
  }
234
234
  }
@@ -295,9 +295,7 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
295
295
  });
296
296
  }
297
297
  function maybeCacheResult(result, setResult) {
298
- if (result.data) {
299
- result.data = removeMetadataFieldsFromResult(result.data, onEntity);
300
- }
298
+ result.data &&= removeMetadataFieldsFromResult(result.data, onEntity);
301
299
  // we only use the global ttl if no currentTtl has been determined.
302
300
  let finalTtl = currentTtl ?? globalTtl;
303
301
  if (onTtl) {
@@ -366,9 +364,7 @@ function handleAsyncIterableResult(handler) {
366
364
  }
367
365
  const newResult = { ...payload.result };
368
366
  // Handle initial/single result
369
- if (newResult.data) {
370
- newResult.data = removeMetadataFieldsFromResult(newResult.data);
371
- }
367
+ newResult.data &&= removeMetadataFieldsFromResult(newResult.data);
372
368
  // Handle Incremental results
373
369
  if ('hasNext' in newResult && newResult.incremental) {
374
370
  newResult.incremental = newResult.incremental.map(value => {
@@ -445,14 +441,15 @@ function removeMetadataFieldsFromResult(data, onEntity) {
445
441
  }
446
442
  // clone the data to avoid mutation
447
443
  data = { ...data };
448
- const typename = data.__responseCacheTypeName ?? data.__typename;
444
+ const typename = data['__responseCacheTypeName'] ?? data['__typename'];
449
445
  if (typeof typename === 'string') {
450
446
  const entity = { typename };
451
- delete data.__responseCacheTypeName;
452
- if (data.__responseCacheId &&
453
- (typeof data.__responseCacheId === 'string' || typeof data.__responseCacheId === 'number')) {
454
- entity.id = data.__responseCacheId;
455
- delete data.__responseCacheId;
447
+ delete data['__responseCacheTypeName'];
448
+ if (data['__responseCacheId'] &&
449
+ (typeof data['__responseCacheId'] === 'string' ||
450
+ typeof data['__responseCacheId'] === 'number')) {
451
+ entity.id = data['__responseCacheId'];
452
+ delete data['__responseCacheId'];
456
453
  }
457
454
  onEntity?.(entity, data);
458
455
  }
@@ -5,8 +5,8 @@ export function hashSHA256(text) {
5
5
  return handleMaybePromise(() => crypto.subtle.digest({ name: 'SHA-256' }, inputUint8Array), arrayBuf => {
6
6
  const outputUint8Array = new Uint8Array(arrayBuf);
7
7
  let hash = '';
8
- for (let i = 0, l = outputUint8Array.length; i < l; i++) {
9
- const hex = outputUint8Array[i].toString(16);
8
+ for (const hexNum of outputUint8Array) {
9
+ const hex = hexNum.toString(16);
10
10
  hash += '00'.slice(0, Math.max(0, 2 - hex.length)) + hex;
11
11
  }
12
12
  return hash;
@@ -5,7 +5,7 @@ export const createInMemoryCache = (params) => {
5
5
  max: params?.max ?? 1000,
6
6
  allowStale: false,
7
7
  noDisposeOnSet: true,
8
- dispose(responseId) {
8
+ dispose(_value, responseId) {
9
9
  purgeResponse(responseId, false);
10
10
  },
11
11
  });
@@ -16,8 +16,13 @@ export const createInMemoryCache = (params) => {
16
16
  // get entities related to the response
17
17
  if (entityIds !== undefined) {
18
18
  for (const entityId of entityIds) {
19
- // remove the response mapping from the entity
20
- entityToResponseIds.get(entityId)?.delete(responseId);
19
+ const responseIds = entityToResponseIds.get(entityId);
20
+ if (responseIds) {
21
+ responseIds.delete(responseId);
22
+ if (responseIds.size === 0) {
23
+ entityToResponseIds.delete(entityId);
24
+ }
25
+ }
21
26
  }
22
27
  // remove all the entity mappings from the response
23
28
  responseIdToEntityIds.delete(responseId);
@@ -69,7 +74,7 @@ export const createInMemoryCache = (params) => {
69
74
  },
70
75
  invalidate(entitiesToRemove) {
71
76
  for (const { typename, id } of entitiesToRemove) {
72
- purgeEntity(id != null ? buildEntityId(typename, id) : typename);
77
+ purgeEntity(id == null ? typename : buildEntityId(typename, id));
73
78
  }
74
79
  },
75
80
  };
package/esm/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import jsonStableStringify from 'fast-json-stable-stringify';
2
2
  import { getOperationAST, isListType, isNonNullType, isUnionType, Kind, print, TypeInfo, visit, visitWithTypeInfo, } from 'graphql';
3
- import { getDocumentString, isAsyncIterable, } from '@envelop/core';
3
+ import { getDocumentString, isAsyncIterable } from '@envelop/core';
4
4
  import { getDirective, MapperKind, mapSchema, memoize1, memoize4, mergeIncrementalResult, } from '@graphql-tools/utils';
5
5
  import { handleMaybePromise } from '@whatwg-node/promise-helpers';
6
6
  import { hashSHA256 } from './hash-sha256.js';
@@ -87,10 +87,9 @@ const getDocumentWithMetadataAndTTL = memoize4(function addTypeNameToDocument(do
87
87
  };
88
88
  return [visit(document, visitWithTypeInfo(typeInfo, visitor)), ttl];
89
89
  });
90
- export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process !== 'undefined'
91
- ? // eslint-disable-next-line dot-notation
92
- process.env['NODE_ENV'] === 'development' || !!process.env['DEBUG']
93
- : false, }) {
90
+ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process === 'undefined'
91
+ ? false
92
+ : process.env['NODE_ENV'] === 'development' || !!process.env['DEBUG'], }) {
94
93
  const cacheFactory = typeof cache === 'function' ? memoize1(cache) : () => cache;
95
94
  const ignoredTypesMap = new Set(ignoredTypes);
96
95
  const typePerSchemaCoordinateMap = new Map();
@@ -127,14 +126,15 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
127
126
  ...(directive && {
128
127
  [MapperKind.COMPOSITE_TYPE]: type => {
129
128
  const cacheControlAnnotations = getDirective(schema, type, 'cacheControl');
130
- cacheControlAnnotations?.forEach(cacheControl => {
131
- if (cacheControl.maxAge != null) {
132
- ttlPerSchemaCoordinate[type.name] = cacheControl.maxAge * 1000;
129
+ if (cacheControlAnnotations)
130
+ for (const cacheControl of cacheControlAnnotations) {
131
+ if (cacheControl.maxAge != null) {
132
+ ttlPerSchemaCoordinate[type.name] = cacheControl.maxAge * 1000;
133
+ }
134
+ if (cacheControl.scope) {
135
+ scopePerSchemaCoordinate[type.name] = cacheControl.scope;
136
+ }
133
137
  }
134
- if (cacheControl.scope) {
135
- scopePerSchemaCoordinate[type.name] = cacheControl.scope;
136
- }
137
- });
138
138
  return type;
139
139
  },
140
140
  }),
@@ -147,14 +147,15 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
147
147
  }
148
148
  if (directive) {
149
149
  const cacheControlAnnotations = getDirective(schema, fieldConfig, 'cacheControl');
150
- cacheControlAnnotations?.forEach(cacheControl => {
151
- if (cacheControl.maxAge != null) {
152
- ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
150
+ if (cacheControlAnnotations)
151
+ for (const cacheControl of cacheControlAnnotations) {
152
+ if (cacheControl.maxAge != null) {
153
+ ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
154
+ }
155
+ if (cacheControl.scope) {
156
+ scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
157
+ }
153
158
  }
154
- if (cacheControl.scope) {
155
- scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
156
- }
157
- });
158
159
  }
159
160
  return fieldConfig;
160
161
  },
@@ -165,7 +166,6 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
165
166
  return;
166
167
  }
167
168
  const identifier = new Map();
168
- const types = new Set();
169
169
  let currentTtl;
170
170
  let skip = false;
171
171
  const sessionId = session(onExecuteParams.args.contextValue);
@@ -201,7 +201,6 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
201
201
  entity.id = data[idField];
202
202
  }
203
203
  }
204
- types.add(entity.typename);
205
204
  if (entity.typename in ttlPerSchemaCoordinate) {
206
205
  const maybeTtl = ttlPerSchemaCoordinate[entity.typename];
207
206
  currentTtl = calculateTtl(maybeTtl, currentTtl);
@@ -213,13 +212,14 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
213
212
  const fieldData = data[fieldName];
214
213
  if (fieldData == null || (Array.isArray(fieldData) && fieldData.length === 0)) {
215
214
  const inferredTypes = typePerSchemaCoordinateMap.get(`${entity.typename}.${fieldName}`);
216
- inferredTypes?.forEach(inferredType => {
217
- if (inferredType in ttlPerSchemaCoordinate) {
218
- const maybeTtl = ttlPerSchemaCoordinate[inferredType];
219
- currentTtl = calculateTtl(maybeTtl, currentTtl);
215
+ if (inferredTypes)
216
+ for (const inferredType of inferredTypes) {
217
+ if (inferredType in ttlPerSchemaCoordinate) {
218
+ const maybeTtl = ttlPerSchemaCoordinate[inferredType];
219
+ currentTtl = calculateTtl(maybeTtl, currentTtl);
220
+ }
221
+ identifier.set(inferredType, { typename: inferredType });
220
222
  }
221
- identifier.set(inferredType, { typename: inferredType });
222
- });
223
223
  }
224
224
  }
225
225
  }
@@ -286,9 +286,7 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
286
286
  });
287
287
  }
288
288
  function maybeCacheResult(result, setResult) {
289
- if (result.data) {
290
- result.data = removeMetadataFieldsFromResult(result.data, onEntity);
291
- }
289
+ result.data &&= removeMetadataFieldsFromResult(result.data, onEntity);
292
290
  // we only use the global ttl if no currentTtl has been determined.
293
291
  let finalTtl = currentTtl ?? globalTtl;
294
292
  if (onTtl) {
@@ -357,9 +355,7 @@ function handleAsyncIterableResult(handler) {
357
355
  }
358
356
  const newResult = { ...payload.result };
359
357
  // Handle initial/single result
360
- if (newResult.data) {
361
- newResult.data = removeMetadataFieldsFromResult(newResult.data);
362
- }
358
+ newResult.data &&= removeMetadataFieldsFromResult(newResult.data);
363
359
  // Handle Incremental results
364
360
  if ('hasNext' in newResult && newResult.incremental) {
365
361
  newResult.incremental = newResult.incremental.map(value => {
@@ -436,14 +432,15 @@ function removeMetadataFieldsFromResult(data, onEntity) {
436
432
  }
437
433
  // clone the data to avoid mutation
438
434
  data = { ...data };
439
- const typename = data.__responseCacheTypeName ?? data.__typename;
435
+ const typename = data['__responseCacheTypeName'] ?? data['__typename'];
440
436
  if (typeof typename === 'string') {
441
437
  const entity = { typename };
442
- delete data.__responseCacheTypeName;
443
- if (data.__responseCacheId &&
444
- (typeof data.__responseCacheId === 'string' || typeof data.__responseCacheId === 'number')) {
445
- entity.id = data.__responseCacheId;
446
- delete data.__responseCacheId;
438
+ delete data['__responseCacheTypeName'];
439
+ if (data['__responseCacheId'] &&
440
+ (typeof data['__responseCacheId'] === 'string' ||
441
+ typeof data['__responseCacheId'] === 'number')) {
442
+ entity.id = data['__responseCacheId'];
443
+ delete data['__responseCacheId'];
447
444
  }
448
445
  onEntity?.(entity, data);
449
446
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@envelop/response-cache",
3
- "version": "9.1.1",
3
+ "version": "9.3.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
7
- "@envelop/core": "^5.5.1"
6
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
7
+ "@envelop/core": "^5.6.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-tools/utils": "^11.0.0",
10
+ "@graphql-tools/utils": "^11.2.0",
11
11
  "@whatwg-node/fetch": "^0.10.0",
12
12
  "@whatwg-node/promise-helpers": "^1.2.4",
13
13
  "fast-json-stable-stringify": "^2.1.0",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/graphql-hive/envelop.git",
20
- "directory": "packages/plugins/response-cache"
19
+ "url": "https://github.com/graphql-hive/graphql-yoga.git",
20
+ "directory": "packages/envelop/plugins/response-cache"
21
21
  },
22
22
  "author": "Kamil Kisiela <kamilkisiela@gmail.com>",
23
23
  "license": "MIT",
@@ -1,2 +1,2 @@
1
- import { MaybePromise } from '@whatwg-node/promise-helpers';
1
+ import type { MaybePromise } from '@whatwg-node/promise-helpers';
2
2
  export declare function hashSHA256(text: string): MaybePromise<string>;
@@ -1,2 +1,2 @@
1
- import { MaybePromise } from '@whatwg-node/promise-helpers';
1
+ import type { MaybePromise } from '@whatwg-node/promise-helpers';
2
2
  export declare function hashSHA256(text: string): MaybePromise<string>;
@@ -1,6 +1,6 @@
1
- import { ExecutionArgs } from 'graphql';
2
- import { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
3
- import { MaybePromise } from '@whatwg-node/promise-helpers';
1
+ import type { ExecutionArgs } from 'graphql';
2
+ import type { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
3
+ import type { MaybePromise } from '@whatwg-node/promise-helpers';
4
4
  import type { Cache, CacheEntityRecord } from './cache.cjs';
5
5
  /**
6
6
  * Function for building the response cache key based on the input parameters
@@ -122,7 +122,7 @@ export type ResponseCacheOnTtlFunction<PluginContext> = (payload: {
122
122
  */
123
123
  export declare const defaultBuildResponseCacheKey: (params: {
124
124
  documentString: string;
125
- variableValues: ExecutionArgs["variableValues"];
125
+ variableValues: ExecutionArgs['variableValues'];
126
126
  operationName?: Maybe<string>;
127
127
  sessionId: Maybe<string>;
128
128
  }) => MaybePromise<string>;
@@ -151,6 +151,6 @@ export type ResponseCacheExtensions = {
151
151
  export type ResponseCacheExecutionResult = ExecutionResult<ObjMap<unknown>, {
152
152
  responseCache?: ResponseCacheExtensions;
153
153
  }>;
154
- export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata, }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;
154
+ export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;
155
155
  export declare function resultWithMetadata(result: ExecutionResult, metadata: ResponseCacheExtensions): ResponseCacheExecutionResult;
156
156
  export declare const cacheControlDirective = "\n enum CacheControlScope {\n PUBLIC\n PRIVATE\n }\n\n directive @cacheControl(maxAge: Int, scope: CacheControlScope) on FIELD_DEFINITION | OBJECT\n";
@@ -1,6 +1,6 @@
1
- import { ExecutionArgs } from 'graphql';
2
- import { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
3
- import { MaybePromise } from '@whatwg-node/promise-helpers';
1
+ import type { ExecutionArgs } from 'graphql';
2
+ import type { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
3
+ import type { MaybePromise } from '@whatwg-node/promise-helpers';
4
4
  import type { Cache, CacheEntityRecord } from './cache.js';
5
5
  /**
6
6
  * Function for building the response cache key based on the input parameters
@@ -122,7 +122,7 @@ export type ResponseCacheOnTtlFunction<PluginContext> = (payload: {
122
122
  */
123
123
  export declare const defaultBuildResponseCacheKey: (params: {
124
124
  documentString: string;
125
- variableValues: ExecutionArgs["variableValues"];
125
+ variableValues: ExecutionArgs['variableValues'];
126
126
  operationName?: Maybe<string>;
127
127
  sessionId: Maybe<string>;
128
128
  }) => MaybePromise<string>;
@@ -151,6 +151,6 @@ export type ResponseCacheExtensions = {
151
151
  export type ResponseCacheExecutionResult = ExecutionResult<ObjMap<unknown>, {
152
152
  responseCache?: ResponseCacheExtensions;
153
153
  }>;
154
- export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata, }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;
154
+ export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;
155
155
  export declare function resultWithMetadata(result: ExecutionResult, metadata: ResponseCacheExtensions): ResponseCacheExecutionResult;
156
156
  export declare const cacheControlDirective = "\n enum CacheControlScope {\n PUBLIC\n PRIVATE\n }\n\n directive @cacheControl(maxAge: Int, scope: CacheControlScope) on FIELD_DEFINITION | OBJECT\n";