@graphql-box/cache-manager 5.4.0 → 5.4.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graphql-box/cache-manager",
3
3
  "description": "The GraphQL Box cache manager module.",
4
- "version": "5.4.0",
4
+ "version": "5.4.2",
5
5
  "author": "Dylan Aubrey",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/graphql-box",
@@ -36,8 +36,8 @@
36
36
  "cacheability": "^4.0.27",
37
37
  "core-js": "^3.39.0",
38
38
  "lodash-es": "^4.17.21",
39
- "@graphql-box/core": "5.4.0",
40
- "@graphql-box/helpers": "5.4.0"
39
+ "@graphql-box/core": "5.4.1",
40
+ "@graphql-box/helpers": "5.4.1"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@cachemap/core": "<6",
@@ -50,7 +50,7 @@
50
50
  "cts-types": "^0.0.8",
51
51
  "del-cli": "^6.0.0",
52
52
  "graphql": "^16.9.0",
53
- "@graphql-box/test-utils": "5.4.0"
53
+ "@graphql-box/test-utils": "5.4.1"
54
54
  },
55
55
  "keywords": [
56
56
  "client",
package/src/index.test.ts CHANGED
@@ -72,7 +72,7 @@ describe('@graphql-box/cache-manager >>', () => {
72
72
  });
73
73
 
74
74
  it('correct cache data', async () => {
75
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
75
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
76
76
  });
77
77
  });
78
78
 
@@ -119,7 +119,7 @@ describe('@graphql-box/cache-manager >>', () => {
119
119
  });
120
120
 
121
121
  it('correct cache data', async () => {
122
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
122
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
123
123
  });
124
124
  });
125
125
  });
@@ -162,7 +162,7 @@ describe('@graphql-box/cache-manager >>', () => {
162
162
  });
163
163
 
164
164
  it('correct cache data', async () => {
165
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
165
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
166
166
  });
167
167
  });
168
168
 
@@ -206,7 +206,7 @@ describe('@graphql-box/cache-manager >>', () => {
206
206
  });
207
207
 
208
208
  it('correct cache data', async () => {
209
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
209
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
210
210
  });
211
211
  });
212
212
  });
@@ -253,7 +253,7 @@ describe('@graphql-box/cache-manager >>', () => {
253
253
  });
254
254
 
255
255
  it('correct cache data', async () => {
256
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
256
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
257
257
  });
258
258
  });
259
259
 
@@ -294,7 +294,7 @@ describe('@graphql-box/cache-manager >>', () => {
294
294
  });
295
295
 
296
296
  it('correct cache data', async () => {
297
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
297
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
298
298
  });
299
299
  });
300
300
  });
@@ -335,7 +335,7 @@ describe('@graphql-box/cache-manager >>', () => {
335
335
  });
336
336
 
337
337
  it('correct cache data', async () => {
338
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
338
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
339
339
  });
340
340
  });
341
341
 
@@ -379,7 +379,7 @@ describe('@graphql-box/cache-manager >>', () => {
379
379
  });
380
380
 
381
381
  it('correct cache data', async () => {
382
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
382
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
383
383
  });
384
384
  });
385
385
  });
@@ -420,7 +420,7 @@ describe('@graphql-box/cache-manager >>', () => {
420
420
  });
421
421
 
422
422
  it('correct cache data', async () => {
423
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
423
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
424
424
  });
425
425
  });
426
426
 
@@ -462,7 +462,7 @@ describe('@graphql-box/cache-manager >>', () => {
462
462
  });
463
463
 
464
464
  it('correct cache data', async () => {
465
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
465
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
466
466
  });
467
467
  });
468
468
  });
@@ -525,7 +525,7 @@ describe('@graphql-box/cache-manager >>', () => {
525
525
  });
526
526
 
527
527
  it('correct cache data', async () => {
528
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
528
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
529
529
  });
530
530
  });
531
531
 
@@ -586,7 +586,7 @@ describe('@graphql-box/cache-manager >>', () => {
586
586
  });
587
587
 
588
588
  it('correct cache data', async () => {
589
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
589
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
590
590
  });
591
591
  });
592
592
  });
@@ -647,7 +647,7 @@ describe('@graphql-box/cache-manager >>', () => {
647
647
  });
648
648
 
649
649
  it('correct cache data', async () => {
650
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
650
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
651
651
  });
652
652
  });
653
653
 
@@ -711,7 +711,7 @@ describe('@graphql-box/cache-manager >>', () => {
711
711
  });
712
712
 
713
713
  it('correct cache data', async () => {
714
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
714
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
715
715
  });
716
716
  });
717
717
  });
@@ -772,7 +772,7 @@ describe('@graphql-box/cache-manager >>', () => {
772
772
  });
773
773
 
774
774
  it('correct cache data', async () => {
775
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
775
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
776
776
  });
777
777
  });
778
778
 
@@ -834,7 +834,7 @@ describe('@graphql-box/cache-manager >>', () => {
834
834
  });
835
835
 
836
836
  it('correct cache data', async () => {
837
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
837
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
838
838
  });
839
839
  });
840
840
  });
@@ -915,7 +915,7 @@ describe('@graphql-box/cache-manager >>', () => {
915
915
  });
916
916
 
917
917
  it('correct cache data', async () => {
918
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
918
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
919
919
  });
920
920
  });
921
921
  });
@@ -1121,7 +1121,7 @@ describe('@graphql-box/cache-manager >>', () => {
1121
1121
  });
1122
1122
 
1123
1123
  it('correct cache data', async () => {
1124
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1124
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1125
1125
  });
1126
1126
  });
1127
1127
 
@@ -1177,7 +1177,7 @@ describe('@graphql-box/cache-manager >>', () => {
1177
1177
  });
1178
1178
 
1179
1179
  it('correct cache data', async () => {
1180
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1180
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1181
1181
  });
1182
1182
  });
1183
1183
 
@@ -1231,7 +1231,7 @@ describe('@graphql-box/cache-manager >>', () => {
1231
1231
  });
1232
1232
 
1233
1233
  it('correct cache data', async () => {
1234
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1234
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1235
1235
  });
1236
1236
  });
1237
1237
 
@@ -1298,7 +1298,7 @@ describe('@graphql-box/cache-manager >>', () => {
1298
1298
  });
1299
1299
 
1300
1300
  it('correct cache data', async () => {
1301
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1301
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1302
1302
  });
1303
1303
  });
1304
1304
  });
@@ -1355,7 +1355,7 @@ describe('@graphql-box/cache-manager >>', () => {
1355
1355
  });
1356
1356
 
1357
1357
  it('correct cache data', async () => {
1358
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1358
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1359
1359
  });
1360
1360
 
1361
1361
  it('correct partial data', () => {
@@ -1415,7 +1415,7 @@ describe('@graphql-box/cache-manager >>', () => {
1415
1415
  });
1416
1416
 
1417
1417
  it('correct cache data', async () => {
1418
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1418
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1419
1419
  });
1420
1420
 
1421
1421
  it('correct partial data', () => {
@@ -1478,7 +1478,7 @@ describe('@graphql-box/cache-manager >>', () => {
1478
1478
  });
1479
1479
 
1480
1480
  it('correct cache data', async () => {
1481
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1481
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1482
1482
  });
1483
1483
 
1484
1484
  it('correct partial data', () => {
@@ -1539,7 +1539,7 @@ describe('@graphql-box/cache-manager >>', () => {
1539
1539
  });
1540
1540
 
1541
1541
  it('correct cache data', async () => {
1542
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1542
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1543
1543
  });
1544
1544
 
1545
1545
  it('correct partial data', () => {
@@ -1597,7 +1597,7 @@ describe('@graphql-box/cache-manager >>', () => {
1597
1597
  });
1598
1598
 
1599
1599
  it('correct cache data', async () => {
1600
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1600
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1601
1601
  });
1602
1602
 
1603
1603
  it('correct partial data', () => {
@@ -1655,7 +1655,7 @@ describe('@graphql-box/cache-manager >>', () => {
1655
1655
  });
1656
1656
 
1657
1657
  it('correct cache data', async () => {
1658
- await expect(cacheManager.cache.export()).resolves.toMatchSnapshot();
1658
+ await expect(cacheManager.cache?.export()).resolves.toMatchSnapshot();
1659
1659
  });
1660
1660
 
1661
1661
  it('correct partial data', () => {
package/src/main.ts CHANGED
@@ -231,7 +231,7 @@ export class CacheManager implements CacheManagerDef {
231
231
  ]);
232
232
  }
233
233
 
234
- private readonly _cache: Core;
234
+ private _cache: Core | undefined;
235
235
  private readonly _cacheTiersEnabled: CacheTiersEnabled = { entity: false, queryResponse: true, requestPath: false };
236
236
  private readonly _cascadeCacheControl: boolean;
237
237
  private readonly _fallbackOperationCacheability: string;
@@ -256,7 +256,19 @@ export class CacheManager implements CacheManagerDef {
256
256
  throw new GroupedError('@graphql-box/cache-manager argument validation errors.', errors);
257
257
  }
258
258
 
259
- this._cache = options.cache;
259
+ if (typeof options.cache === 'function') {
260
+ void options
261
+ .cache()
262
+ .then(cache => {
263
+ this._cache = cache;
264
+ })
265
+ .catch((error: unknown) => {
266
+ throw error;
267
+ });
268
+ } else {
269
+ this._cache = options.cache;
270
+ }
271
+
260
272
  this._cacheTiersEnabled = { ...this._cacheTiersEnabled, ...options.cacheTiersEnabled };
261
273
  this._cascadeCacheControl = options.cascadeCacheControl ?? false;
262
274
  this._fallbackOperationCacheability = options.fallbackOperationCacheability ?? NO_CACHE;
@@ -321,7 +333,7 @@ export class CacheManager implements CacheManagerDef {
321
333
  };
322
334
  }
323
335
 
324
- get cache(): Core {
336
+ get cache(): Core | undefined {
325
337
  return this._cache;
326
338
  }
327
339
 
@@ -744,7 +756,7 @@ export class CacheManager implements CacheManagerDef {
744
756
  _options: RequestOptions,
745
757
  _context: CacheManagerContext & { requestFieldCacheKey?: string },
746
758
  ): Promise<T | undefined> {
747
- return this._cache.get<T>(`${cacheType}::${hash}`);
759
+ return this._cache?.get<T>(`${cacheType}::${hash}`);
748
760
  }
749
761
 
750
762
  private _getPartialQueryResponse(hash: string): PartialQueryResponse | undefined {
@@ -755,7 +767,7 @@ export class CacheManager implements CacheManagerDef {
755
767
 
756
768
  private async _hasCacheEntry(cacheType: CacheTypes, hash: string): Promise<Cacheability | false> {
757
769
  try {
758
- return await this._cache.has(`${cacheType}::${hash}`);
770
+ return (await this._cache?.has(`${cacheType}::${hash}`)) ?? false;
759
771
  } catch {
760
772
  return false;
761
773
  }
@@ -1044,7 +1056,7 @@ export class CacheManager implements CacheManagerDef {
1044
1056
  _context: CacheManagerContext & { requestFieldCacheKey?: string },
1045
1057
  ): Promise<void> {
1046
1058
  try {
1047
- await this._cache.set(`${cacheType}::${hash}`, structuredClone(value), cachemapOptions);
1059
+ await this._cache?.set(`${cacheType}::${hash}`, structuredClone(value), cachemapOptions);
1048
1060
  } catch {
1049
1061
  // no catch
1050
1062
  }
package/src/types.ts CHANGED
@@ -26,7 +26,7 @@ export interface UserOptions {
26
26
  * The cache to use for storing query responses, data entities,
27
27
  * and request field paths.
28
28
  */
29
- cache: Core;
29
+ cache: Core | (() => Promise<Core>);
30
30
  /**
31
31
  * Whether to enable/disable any/all the three cache tiers
32
32
  * the CacheManager uses. All three are enabled by default.
@@ -161,7 +161,7 @@ export interface QueryResponseCacheEntry {
161
161
 
162
162
  export interface CacheManagerDef {
163
163
  analyzeQuery(requestData: RequestData, options: RequestOptions, context: RequestContext): Promise<AnalyzeQueryResult>;
164
- cache: Core;
164
+ cache: Core | undefined;
165
165
  cacheQuery(
166
166
  requestData: RequestData,
167
167
  updatedRequestData: RequestData | undefined,