@graphql-box/cache-manager 2.1.0 → 2.1.4

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/src/main/index.ts CHANGED
@@ -36,7 +36,7 @@ import {
36
36
  import Cacheability from "cacheability";
37
37
  import { FieldNode, print } from "graphql";
38
38
  import { cloneDeep, get, isArray, isNumber, isObjectLike, isPlainObject, isUndefined, set, unset } from "lodash";
39
- import { CACHE_CONTROL, HEADER_CACHE_CONTROL, HEADER_NO_CACHE, METADATA, NO_CACHE } from "../consts";
39
+ import { CACHE_CONTROL, HEADER_NO_CACHE, METADATA, NO_CACHE } from "../consts";
40
40
  import { logCacheEntry, logCacheQuery, logPartialCompiled } from "../debug";
41
41
  import {
42
42
  AnalyzeQueryResult,
@@ -66,6 +66,7 @@ import {
66
66
  TypeNames,
67
67
  UserOptions,
68
68
  } from "../defs";
69
+ import deriveOpCacheability from "../helpers/deriveOpCacheability";
69
70
 
70
71
  export class CacheManager implements CacheManagerDef {
71
72
  public static async init(options: InitOptions): Promise<CacheManager> {
@@ -101,7 +102,7 @@ export class CacheManager implements CacheManagerDef {
101
102
  CacheManager._getFieldDataFromAncestor(requestFieldPathData, propNameOrIndex);
102
103
 
103
104
  const typeNames = {
104
- dataTypeName: dataEntityData.__typename || requestFieldPathData.__typename,
105
+ dataTypeName: dataEntityData?.__typename || requestFieldPathData?.__typename,
105
106
  fieldTypeName: typeName,
106
107
  };
107
108
 
@@ -556,10 +557,19 @@ export class CacheManager implements CacheManagerDef {
556
557
  { operation }: RequestContext,
557
558
  ): CacheMetadata {
558
559
  const cacheMetadata = new Map();
559
- const cacheControl = (headers && headers.get(HEADER_CACHE_CONTROL)) || this._fallbackOperationCacheability;
560
- const cacheability = new Cacheability({ cacheControl });
560
+
561
+ const cacheability = deriveOpCacheability({
562
+ _cacheMetadata,
563
+ fallback: this._fallbackOperationCacheability,
564
+ headers,
565
+ });
566
+
561
567
  cacheMetadata.set(operation, cacheability);
562
- if (_cacheMetadata) rehydrateCacheMetadata(_cacheMetadata, cacheMetadata);
568
+
569
+ if (_cacheMetadata) {
570
+ rehydrateCacheMetadata(_cacheMetadata, cacheMetadata);
571
+ }
572
+
563
573
  return cacheMetadata;
564
574
  }
565
575