@graphql-box/cache-manager 3.1.2 → 3.2.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.
Files changed (52) hide show
  1. package/lib/browser/index.js +1 -1
  2. package/lib/browser/index.js.map +1 -1
  3. package/lib/browser/production.analysis.txt +38 -50
  4. package/lib/main/helpers/createFragmentSpreadChecklist.js +10 -15
  5. package/lib/main/helpers/createFragmentSpreadChecklist.js.map +1 -1
  6. package/lib/main/helpers/filterField.js +1 -3
  7. package/lib/main/helpers/filterField.js.map +1 -1
  8. package/lib/main/helpers/filterFragmentDefinitions.js +3 -3
  9. package/lib/main/helpers/filterFragmentDefinitions.js.map +1 -1
  10. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js +1 -3
  11. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -1
  12. package/lib/main/helpers/filterQuery.js +2 -4
  13. package/lib/main/helpers/filterQuery.js.map +1 -1
  14. package/lib/main/main/index.js +9 -7
  15. package/lib/main/main/index.js.map +1 -1
  16. package/lib/module/helpers/createFragmentSpreadChecklist.js +10 -14
  17. package/lib/module/helpers/createFragmentSpreadChecklist.js.map +1 -1
  18. package/lib/module/helpers/filterField.js +1 -2
  19. package/lib/module/helpers/filterField.js.map +1 -1
  20. package/lib/module/helpers/filterFragmentDefinitions.js +4 -4
  21. package/lib/module/helpers/filterFragmentDefinitions.js.map +1 -1
  22. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js +1 -2
  23. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -1
  24. package/lib/module/helpers/filterQuery.js +2 -3
  25. package/lib/module/helpers/filterQuery.js.map +1 -1
  26. package/lib/module/main/index.js +6 -3
  27. package/lib/module/main/index.js.map +1 -1
  28. package/lib/types/defs/index.d.ts +3 -16
  29. package/lib/types/defs/index.d.ts.map +1 -1
  30. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts +2 -1
  31. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts.map +1 -1
  32. package/lib/types/helpers/filterField.d.ts.map +1 -1
  33. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts +2 -1
  34. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +1 -1
  35. package/lib/types/helpers/filterQuery.d.ts.map +1 -1
  36. package/lib/types/main/index.d.ts +3 -2
  37. package/lib/types/main/index.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/defs/index.ts +8 -17
  40. package/src/helpers/createFragmentSpreadChecklist.ts +3 -3
  41. package/src/helpers/filterField.ts +8 -2
  42. package/src/helpers/filterFragmentDefinitions.ts +2 -2
  43. package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +2 -3
  44. package/src/helpers/filterQuery.ts +7 -3
  45. package/src/main/index.ts +13 -4
  46. package/lib/main/helpers/buildKeysAndPaths.js +0 -73
  47. package/lib/main/helpers/buildKeysAndPaths.js.map +0 -1
  48. package/lib/module/helpers/buildKeysAndPaths.js +0 -54
  49. package/lib/module/helpers/buildKeysAndPaths.js.map +0 -1
  50. package/lib/types/helpers/buildKeysAndPaths.d.ts +0 -10
  51. package/lib/types/helpers/buildKeysAndPaths.d.ts.map +0 -1
  52. package/src/helpers/buildKeysAndPaths.ts +0 -71
@@ -1,8 +1,14 @@
1
1
  import { TYPE_NAME_KEY } from "@graphql-box/core";
2
- import { FRAGMENT_SPREAD, deleteChildFields, getChildFields, getName, hasChildFields } from "@graphql-box/helpers";
2
+ import {
3
+ FRAGMENT_SPREAD,
4
+ buildFieldKeysAndPaths,
5
+ deleteChildFields,
6
+ getChildFields,
7
+ getName,
8
+ hasChildFields,
9
+ } from "@graphql-box/helpers";
3
10
  import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
4
11
  import { CacheManagerContext, FieldPathChecklist, FragmentSpreadFieldCounter } from "../defs";
5
- import { buildFieldKeysAndPaths } from "./buildKeysAndPaths";
6
12
  import checkFieldPathChecklist from "./checkFieldPathChecklist";
7
13
  import { FragmentSpreadCheckist } from "./createFragmentSpreadChecklist";
8
14
  import filterFragmentSpreads from "./filterFragmentSpreads";
@@ -1,4 +1,4 @@
1
- import { deleteFragmentDefinitions, getFragmentDefinitions } from "@graphql-box/helpers";
1
+ import { deleteFragmentDefinitions } from "@graphql-box/helpers";
2
2
  import { DocumentNode } from "graphql";
3
3
  import { keys } from "lodash";
4
4
  import { CacheManagerContext, FieldPathChecklist } from "../defs";
@@ -22,7 +22,7 @@ export default (
22
22
  [],
23
23
  );
24
24
 
25
- const fragmentDefinitions = getFragmentDefinitions(ast) ?? {};
25
+ const { fragmentDefinitions = {} } = context;
26
26
 
27
27
  definitionsToFilter.forEach(({ name, path }) => {
28
28
  const fragmentDefinition = fragmentDefinitions[name];
@@ -1,9 +1,8 @@
1
1
  import { PlainObjectMap } from "@graphql-box/core";
2
- import { getName, resolveFragments } from "@graphql-box/helpers";
2
+ import { KeysAndPaths, buildFieldKeysAndPaths, getName, resolveFragments } from "@graphql-box/helpers";
3
3
  import { FieldNode, SelectionNode } from "graphql";
4
4
  import { keys } from "lodash";
5
- import { CacheManagerContext, KeysAndPaths } from "../defs";
6
- import { buildFieldKeysAndPaths } from "./buildKeysAndPaths";
5
+ import { CacheManagerContext } from "../defs";
7
6
 
8
7
  export default (
9
8
  fieldData: PlainObjectMap,
@@ -1,7 +1,11 @@
1
1
  import { RequestData } from "@graphql-box/core";
2
- import { deleteChildFields, getChildFields, getOperationDefinitions } from "@graphql-box/helpers";
2
+ import {
3
+ buildFieldKeysAndPaths,
4
+ deleteChildFields,
5
+ getChildFields,
6
+ getOperationDefinitions,
7
+ } from "@graphql-box/helpers";
3
8
  import { CacheManagerContext, CachedResponseData } from "../defs";
4
- import { buildFieldKeysAndPaths } from "./buildKeysAndPaths";
5
9
  import createFragmentSpreadChecklist from "./createFragmentSpreadChecklist";
6
10
  import filterField from "./filterField";
7
11
  import filterFragmentDefinitions from "./filterFragmentDefinitions";
@@ -16,7 +20,7 @@ export default (requestData: RequestData, { fieldPathChecklist }: CachedResponse
16
20
  return ast;
17
21
  }
18
22
 
19
- const fragmentSpreadChecklist = createFragmentSpreadChecklist(requestData);
23
+ const fragmentSpreadChecklist = createFragmentSpreadChecklist(requestData, context);
20
24
 
21
25
  for (let i = fieldsAndTypeNames.length - 1; i >= 0; i -= 1) {
22
26
  const { fieldNode } = fieldsAndTypeNames[i];
package/src/main/index.ts CHANGED
@@ -18,6 +18,8 @@ import {
18
18
  } from "@graphql-box/core";
19
19
  import {
20
20
  FRAGMENT_SPREAD,
21
+ KeysAndPaths,
22
+ buildFieldKeysAndPaths,
21
23
  dehydrateCacheMetadata,
22
24
  getChildFields,
23
25
  getFragmentDefinitions,
@@ -49,7 +51,6 @@ import {
49
51
  FieldCount,
50
52
  FieldPathChecklist,
51
53
  FieldPathChecklistValue,
52
- KeysAndPaths,
53
54
  MergedCachedFieldData,
54
55
  PartialQueryResponse,
55
56
  PartialQueryResponses,
@@ -58,7 +59,6 @@ import {
58
59
  TypeNamesAndKind,
59
60
  UserOptions,
60
61
  } from "../defs";
61
- import { buildFieldKeysAndPaths } from "../helpers/buildKeysAndPaths";
62
62
  import deriveOpCacheability from "../helpers/deriveOpCacheability";
63
63
  import filterOutPropsWithArgsOrDirectives from "../helpers/filterOutPropsWithArgsOrDirectives";
64
64
  import filterQuery from "../helpers/filterQuery";
@@ -284,14 +284,14 @@ export class CacheManager implements CacheManagerDef {
284
284
 
285
285
  public async cacheQuery(
286
286
  requestData: RequestData,
287
- updatedRequestData: RequestData,
287
+ updatedRequestData: RequestData | undefined,
288
288
  rawResponseData: RawResponseDataWithMaybeCacheMetadata,
289
289
  options: RequestOptions,
290
290
  context: RequestContext,
291
291
  ): Promise<ResponseData> {
292
292
  const cacheManagerContext: CacheManagerContext = {
293
293
  ...context,
294
- fragmentDefinitions: getFragmentDefinitions(updatedRequestData.ast),
294
+ fragmentDefinitions: getFragmentDefinitions((updatedRequestData ?? requestData).ast),
295
295
  typeIDKey: this._typeIDKey,
296
296
  };
297
297
 
@@ -345,6 +345,15 @@ export class CacheManager implements CacheManagerDef {
345
345
  this._partialQueryResponses.delete(hash);
346
346
  }
347
347
 
348
+ public async setQueryResponseCacheEntry(
349
+ requestData: RequestData,
350
+ responseData: ResponseData,
351
+ options: RequestOptions,
352
+ context: CacheManagerContext,
353
+ ): Promise<void> {
354
+ return this._setQueryResponseCacheEntry(requestData.hash, responseData, options, context);
355
+ }
356
+
348
357
  private async _analyzeFieldNode(
349
358
  fieldNode: FieldNode,
350
359
  cachedAncestorFieldData: CachedAncestorFieldData,
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.buildFieldKeysAndPaths = exports.buildRequestFieldCacheKey = exports.buildKey = void 0;
9
-
10
- var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
11
-
12
- var _helpers = require("@graphql-box/helpers");
13
-
14
- const buildKey = (path, key) => {
15
- const paths = [];
16
-
17
- if (path.length) {
18
- paths.push(path);
19
- }
20
-
21
- paths.push(key);
22
- return paths.join(".");
23
- };
24
-
25
- exports.buildKey = buildKey;
26
-
27
- const buildRequestFieldCacheKey = (name, requestFieldCacheKey, args, directives, index) => {
28
- var _directives$inherited, _directives$own;
29
-
30
- let key = `${(0, _isNumber2.default)(index) ? index : name}`;
31
-
32
- if (args) {
33
- key = `${key}(${JSON.stringify(args)})`;
34
- }
35
-
36
- if (directives !== null && directives !== void 0 && (_directives$inherited = directives.inherited) !== null && _directives$inherited !== void 0 && _directives$inherited.length) {
37
- key = `${directives.inherited.join(" ")} ${key}`;
38
- }
39
-
40
- if (directives !== null && directives !== void 0 && (_directives$own = directives.own) !== null && _directives$own !== void 0 && _directives$own.length) {
41
- key = `${key} ${directives.own.join(" ")}`;
42
- }
43
-
44
- return buildKey(requestFieldCacheKey, key);
45
- };
46
-
47
- exports.buildRequestFieldCacheKey = buildRequestFieldCacheKey;
48
-
49
- const buildFieldKeysAndPaths = (field, options, context) => {
50
- const name = (0, _helpers.getName)(field);
51
- const {
52
- index,
53
- requestFieldCacheKey = "",
54
- requestFieldPath = "",
55
- responseDataPath = ""
56
- } = options;
57
- const fieldAliasOrName = (0, _helpers.getAlias)(field) || name;
58
- const updatedRequestFieldPath = (0, _isNumber2.default)(index) ? requestFieldPath : buildKey(requestFieldPath, fieldAliasOrName);
59
- const fieldTypeInfo = context.fieldTypeMap.get(updatedRequestFieldPath);
60
- const updatedRequestFieldCacheKey = buildRequestFieldCacheKey(name, requestFieldCacheKey, (0, _helpers.getArguments)(field), fieldTypeInfo === null || fieldTypeInfo === void 0 ? void 0 : fieldTypeInfo.directives, index);
61
- const propNameOrIndex = (0, _isNumber2.default)(index) ? index : fieldAliasOrName;
62
- const updatedResponseDataPath = buildKey(responseDataPath, propNameOrIndex);
63
- return {
64
- hashedRequestFieldCacheKey: (0, _helpers.hashRequest)(updatedRequestFieldCacheKey),
65
- propNameOrIndex,
66
- requestFieldCacheKey: updatedRequestFieldCacheKey,
67
- requestFieldPath: updatedRequestFieldPath,
68
- responseDataPath: updatedResponseDataPath
69
- };
70
- };
71
-
72
- exports.buildFieldKeysAndPaths = buildFieldKeysAndPaths;
73
- //# sourceMappingURL=buildKeysAndPaths.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/helpers/buildKeysAndPaths.ts"],"names":["buildKey","path","key","paths","length","push","join","buildRequestFieldCacheKey","name","requestFieldCacheKey","args","directives","index","JSON","stringify","inherited","own","buildFieldKeysAndPaths","field","options","context","requestFieldPath","responseDataPath","fieldAliasOrName","updatedRequestFieldPath","fieldTypeInfo","fieldTypeMap","get","updatedRequestFieldCacheKey","propNameOrIndex","updatedResponseDataPath","hashedRequestFieldCacheKey"],"mappings":";;;;;;;;;;;AACA;;AAKO,MAAMA,QAAQ,GAAG,CAACC,IAAD,EAAeC,GAAf,KAAwC;AAC9D,QA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,IAAAA,gBAAgB,GAAG,EAAvD;AAA2DC,IAAAA,gBAAgB,GAAG;AAA9E,MAAqFH,OAA3F;AACA,QAAMI,gBAAgB,GAAG,uBAASL,KAAT,KAAmBV,IAA5C;AACA,QAAMgB,uBAAuB,GAAG,wBAASZ,KAAT,IAAkBS,gBAAlB,GAAqCrB,QAAQ,CAACqB,gBAAD,EAAmBE,gBAAnB,CAA7E;AACA,QAAME,aAAa,GAAGL,OAAO,CAACM,YAAR,CAAqBC,GAArB,CAAyBH,uBAAzB,CAAtB;AAEA,QAAMI,2BAA2B,GAAGrB,yBAAyB,CAC3DC,IAD2D,EAE3DC,oBAF2D,EAG3D,2BAAaS,KAAb,CAH2D,EAI3DO,aAJ2D,aAI3DA,aAJ2D,uBAI3DA,aAAa,CAAEd,UAJ4C,EAK3DC,KAL2D,CAA7D;AAQA,QAAMiB,eAAe,GAAG,wBAASjB,KAAT,IAAkBA,KAAlB,GAA0BW,gBAAlD;AACA,QAAMO,uBAAuB,GAAG9B,QAAQ,CAACsB,gBAAD,EAAmBO,eAAnB,CAAxC;AAEA,SAAO;AACLE,IAAAA,0BAA0B,EAAE,0BAAYH,2BAAZ,CADvB;AAELC,IAAAA,eAFK;AAGLpB,IAAAA,oBAAoB,EAAEmB,2BAHjB;AAILP,IAAAA,gBAAgB,EAAEG,uBAJb;AAKLF,IAAAA,gBAAgB,EAAEQ;AALb,GAAP;AAOD,CA7BM","sourcesContent":["import { FieldTypeInfo, PlainObjectMap } from \"@graphql-box/core\";\nimport { getAlias, getArguments, getName, hashRequest } from \"@graphql-box/helpers\";\nimport { FieldNode } from \"graphql\";\nimport { isNumber } from \"lodash\";\nimport { CacheManagerContext, KeysAndPaths, KeysAndPathsOptions } from \"../defs\";\n\nexport const buildKey = (path: string, key: string | number) => {\n const paths: (string | number)[] = [];\n\n if (path.length) {\n paths.push(path);\n }\n\n paths.push(key);\n return paths.join(\".\");\n};\n\nexport const buildRequestFieldCacheKey = (\n name: string,\n requestFieldCacheKey: string,\n args: PlainObjectMap | undefined,\n directives?: FieldTypeInfo[\"directives\"],\n index?: number,\n) => {\n let key = `${isNumber(index) ? index : name}`;\n\n if (args) {\n key = `${key}(${JSON.stringify(args)})`;\n }\n\n if (directives?.inherited?.length) {\n key = `${directives.inherited.join(\" \")} ${key}`;\n }\n\n if (directives?.own?.length) {\n key = `${key} ${directives.own.join(\" \")}`;\n }\n\n return buildKey(requestFieldCacheKey, key);\n};\n\nexport const buildFieldKeysAndPaths = (\n field: FieldNode,\n options: KeysAndPathsOptions,\n context: CacheManagerContext,\n): KeysAndPaths => {\n const name = getName(field) as FieldNode[\"name\"][\"value\"];\n const { index, requestFieldCacheKey = \"\", requestFieldPath = \"\", responseDataPath = \"\" } = options;\n const fieldAliasOrName = getAlias(field) || name;\n const updatedRequestFieldPath = isNumber(index) ? requestFieldPath : buildKey(requestFieldPath, fieldAliasOrName);\n const fieldTypeInfo = context.fieldTypeMap.get(updatedRequestFieldPath);\n\n const updatedRequestFieldCacheKey = buildRequestFieldCacheKey(\n name,\n requestFieldCacheKey,\n getArguments(field),\n fieldTypeInfo?.directives,\n index,\n );\n\n const propNameOrIndex = isNumber(index) ? index : fieldAliasOrName;\n const updatedResponseDataPath = buildKey(responseDataPath, propNameOrIndex);\n\n return {\n hashedRequestFieldCacheKey: hashRequest(updatedRequestFieldCacheKey),\n propNameOrIndex,\n requestFieldCacheKey: updatedRequestFieldCacheKey,\n requestFieldPath: updatedRequestFieldPath,\n responseDataPath: updatedResponseDataPath,\n };\n};\n"],"file":"buildKeysAndPaths.js"}
@@ -1,54 +0,0 @@
1
- import _isNumber from "lodash/isNumber";
2
- import { getAlias, getArguments, getName, hashRequest } from "@graphql-box/helpers";
3
- export const buildKey = (path, key) => {
4
- const paths = [];
5
-
6
- if (path.length) {
7
- paths.push(path);
8
- }
9
-
10
- paths.push(key);
11
- return paths.join(".");
12
- };
13
- export const buildRequestFieldCacheKey = (name, requestFieldCacheKey, args, directives, index) => {
14
- var _directives$inherited, _directives$own;
15
-
16
- let key = `${_isNumber(index) ? index : name}`;
17
-
18
- if (args) {
19
- key = `${key}(${JSON.stringify(args)})`;
20
- }
21
-
22
- if (directives !== null && directives !== void 0 && (_directives$inherited = directives.inherited) !== null && _directives$inherited !== void 0 && _directives$inherited.length) {
23
- key = `${directives.inherited.join(" ")} ${key}`;
24
- }
25
-
26
- if (directives !== null && directives !== void 0 && (_directives$own = directives.own) !== null && _directives$own !== void 0 && _directives$own.length) {
27
- key = `${key} ${directives.own.join(" ")}`;
28
- }
29
-
30
- return buildKey(requestFieldCacheKey, key);
31
- };
32
- export const buildFieldKeysAndPaths = (field, options, context) => {
33
- const name = getName(field);
34
- const {
35
- index,
36
- requestFieldCacheKey = "",
37
- requestFieldPath = "",
38
- responseDataPath = ""
39
- } = options;
40
- const fieldAliasOrName = getAlias(field) || name;
41
- const updatedRequestFieldPath = _isNumber(index) ? requestFieldPath : buildKey(requestFieldPath, fieldAliasOrName);
42
- const fieldTypeInfo = context.fieldTypeMap.get(updatedRequestFieldPath);
43
- const updatedRequestFieldCacheKey = buildRequestFieldCacheKey(name, requestFieldCacheKey, getArguments(field), fieldTypeInfo === null || fieldTypeInfo === void 0 ? void 0 : fieldTypeInfo.directives, index);
44
- const propNameOrIndex = _isNumber(index) ? index : fieldAliasOrName;
45
- const updatedResponseDataPath = buildKey(responseDataPath, propNameOrIndex);
46
- return {
47
- hashedRequestFieldCacheKey: hashRequest(updatedRequestFieldCacheKey),
48
- propNameOrIndex,
49
- requestFieldCacheKey: updatedRequestFieldCacheKey,
50
- requestFieldPath: updatedRequestFieldPath,
51
- responseDataPath: updatedResponseDataPath
52
- };
53
- };
54
- //# sourceMappingURL=buildKeysAndPaths.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/helpers/buildKeysAndPaths.ts"],"names":["getAlias","getArguments","getName","hashRequest","buildKey","path","key","paths","length","push","join","buildRequestFieldCacheKey","name","requestFieldCacheKey","args","directives","index","JSON","stringify","inherited","own","buildFieldKeysAndPaths","field","options","context","requestFieldPath","responseDataPath","fieldAliasOrName","updatedRequestFieldPath","fieldTypeInfo","fieldTypeMap","get","updatedRequestFieldCacheKey","propNameOrIndex","updatedResponseDataPath","hashedRequestFieldCacheKey"],"mappings":";AACA,SAASA,QAAT,EAAmBC,YAAnB,EAAiCC,OAAjC,EAA0CC,WAA1C,QAA6D,sBAA7D;AAKA,OAAO,MAAMC,QAAQ,GAAG,CAACC,IAAD,EAAeC,GAAf,KAAwC;AAC9D,QAAMC,KAA0B,GAAG,EAAnC;;AAEA,MAAIF,IAAI,CAACG,MAAT,EAAiB;AACfD,IAAAA,KAAK,CAACE,IAAN,CAAWJ,IAAX;AACD;;AAEDE,EAAAA,KAAK,CAACE,IAAN,CAAWH,GAAX;AACA,SAAOC,KAAK,CAACG,IAAN,CAAW,GAAX,CAAP;AACD,CATM;AAWP,OAAO,MAAMC,yBAAyB,GAAG,CACvCC,IADuC,EAEvCC,oBAFuC,EAGvCC,IAHuC,EAIvCC,UAJuC,EAKvCC,KALuC,KAMpC;AAAA;;AACH,MAAIV,GAAG,GAAI,GAAE,UAASU,KAAT,IAAkBA,KAAlB,GAA0BJ,IAAK,EAA5C;;AAEA,MAAIE,IAAJ,EAAU;AACRR,IAAAA,GAAG,GAAI,GAAEA,GAAI,IAAGW,IAAI,CAACC,SAAL,CAAeJ,IAAf,CAAqB,GAArC;AACD;;AAED,MAAIC,UAAJ,aAAIA,UAAJ,wCAAIA,UAAU,CAAEI,SAAhB,kDAAI,sBAAuBX,MAA3B,EAAmC;AACjCF,IAAAA,GAAG,GAAI,GAAES,UAAU,CAACI,SAAX,CAAqBT,IAArB,CAA0B,GAA1B,CAA+B,IAAGJ,GAAI,EAA/C;AACD;;AAED,MAAIS,UAAJ,aAAIA,UAAJ,kCAAIA,UAAU,CAAEK,GAAhB,4CAAI,gBAAiBZ,MAArB,EAA6B;AAC3BF,IAAAA,GAAG,GAAI,GAAEA,GAAI,IAAGS,UAAU,CAACK,GAAX,C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sourcesContent":["import { FieldTypeInfo, PlainObjectMap } from \"@graphql-box/core\";\nimport { getAlias, getArguments, getName, hashRequest } from \"@graphql-box/helpers\";\nimport { FieldNode } from \"graphql\";\nimport { isNumber } from \"lodash\";\nimport { CacheManagerContext, KeysAndPaths, KeysAndPathsOptions } from \"../defs\";\n\nexport const buildKey = (path: string, key: string | number) => {\n const paths: (string | number)[] = [];\n\n if (path.length) {\n paths.push(path);\n }\n\n paths.push(key);\n return paths.join(\".\");\n};\n\nexport const buildRequestFieldCacheKey = (\n name: string,\n requestFieldCacheKey: string,\n args: PlainObjectMap | undefined,\n directives?: FieldTypeInfo[\"directives\"],\n index?: number,\n) => {\n let key = `${isNumber(index) ? index : name}`;\n\n if (args) {\n key = `${key}(${JSON.stringify(args)})`;\n }\n\n if (directives?.inherited?.length) {\n key = `${directives.inherited.join(\" \")} ${key}`;\n }\n\n if (directives?.own?.length) {\n key = `${key} ${directives.own.join(\" \")}`;\n }\n\n return buildKey(requestFieldCacheKey, key);\n};\n\nexport const buildFieldKeysAndPaths = (\n field: FieldNode,\n options: KeysAndPathsOptions,\n context: CacheManagerContext,\n): KeysAndPaths => {\n const name = getName(field) as FieldNode[\"name\"][\"value\"];\n const { index, requestFieldCacheKey = \"\", requestFieldPath = \"\", responseDataPath = \"\" } = options;\n const fieldAliasOrName = getAlias(field) || name;\n const updatedRequestFieldPath = isNumber(index) ? requestFieldPath : buildKey(requestFieldPath, fieldAliasOrName);\n const fieldTypeInfo = context.fieldTypeMap.get(updatedRequestFieldPath);\n\n const updatedRequestFieldCacheKey = buildRequestFieldCacheKey(\n name,\n requestFieldCacheKey,\n getArguments(field),\n fieldTypeInfo?.directives,\n index,\n );\n\n const propNameOrIndex = isNumber(index) ? index : fieldAliasOrName;\n const updatedResponseDataPath = buildKey(responseDataPath, propNameOrIndex);\n\n return {\n hashedRequestFieldCacheKey: hashRequest(updatedRequestFieldCacheKey),\n propNameOrIndex,\n requestFieldCacheKey: updatedRequestFieldCacheKey,\n requestFieldPath: updatedRequestFieldPath,\n responseDataPath: updatedResponseDataPath,\n };\n};\n"],"file":"buildKeysAndPaths.js"}
@@ -1,10 +0,0 @@
1
- import { PlainObjectMap } from "@graphql-box/core";
2
- import { FieldNode } from "graphql";
3
- import { CacheManagerContext, KeysAndPaths, KeysAndPathsOptions } from "../defs";
4
- export declare const buildKey: (path: string, key: string | number) => string;
5
- export declare const buildRequestFieldCacheKey: (name: string, requestFieldCacheKey: string, args: PlainObjectMap | undefined, directives?: {
6
- inherited: string[];
7
- own: string[];
8
- } | undefined, index?: number | undefined) => string;
9
- export declare const buildFieldKeysAndPaths: (field: FieldNode, options: KeysAndPathsOptions, context: CacheManagerContext) => KeysAndPaths;
10
- //# sourceMappingURL=buildKeysAndPaths.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildKeysAndPaths.d.ts","sourceRoot":"","sources":["../../../src/helpers/buildKeysAndPaths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEjF,eAAO,MAAM,QAAQ,SAAU,MAAM,OAAO,MAAM,GAAG,MAAM,WAS1D,CAAC;AAEF,eAAO,MAAM,yBAAyB,SAC9B,MAAM,wBACU,MAAM,QACtB,cAAc,GAAG,SAAS;;;oDAmBjC,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAC1B,SAAS,WACP,mBAAmB,WACnB,mBAAmB,KAC3B,YAyBF,CAAC"}
@@ -1,71 +0,0 @@
1
- import { FieldTypeInfo, PlainObjectMap } from "@graphql-box/core";
2
- import { getAlias, getArguments, getName, hashRequest } from "@graphql-box/helpers";
3
- import { FieldNode } from "graphql";
4
- import { isNumber } from "lodash";
5
- import { CacheManagerContext, KeysAndPaths, KeysAndPathsOptions } from "../defs";
6
-
7
- export const buildKey = (path: string, key: string | number) => {
8
- const paths: (string | number)[] = [];
9
-
10
- if (path.length) {
11
- paths.push(path);
12
- }
13
-
14
- paths.push(key);
15
- return paths.join(".");
16
- };
17
-
18
- export const buildRequestFieldCacheKey = (
19
- name: string,
20
- requestFieldCacheKey: string,
21
- args: PlainObjectMap | undefined,
22
- directives?: FieldTypeInfo["directives"],
23
- index?: number,
24
- ) => {
25
- let key = `${isNumber(index) ? index : name}`;
26
-
27
- if (args) {
28
- key = `${key}(${JSON.stringify(args)})`;
29
- }
30
-
31
- if (directives?.inherited?.length) {
32
- key = `${directives.inherited.join(" ")} ${key}`;
33
- }
34
-
35
- if (directives?.own?.length) {
36
- key = `${key} ${directives.own.join(" ")}`;
37
- }
38
-
39
- return buildKey(requestFieldCacheKey, key);
40
- };
41
-
42
- export const buildFieldKeysAndPaths = (
43
- field: FieldNode,
44
- options: KeysAndPathsOptions,
45
- context: CacheManagerContext,
46
- ): KeysAndPaths => {
47
- const name = getName(field) as FieldNode["name"]["value"];
48
- const { index, requestFieldCacheKey = "", requestFieldPath = "", responseDataPath = "" } = options;
49
- const fieldAliasOrName = getAlias(field) || name;
50
- const updatedRequestFieldPath = isNumber(index) ? requestFieldPath : buildKey(requestFieldPath, fieldAliasOrName);
51
- const fieldTypeInfo = context.fieldTypeMap.get(updatedRequestFieldPath);
52
-
53
- const updatedRequestFieldCacheKey = buildRequestFieldCacheKey(
54
- name,
55
- requestFieldCacheKey,
56
- getArguments(field),
57
- fieldTypeInfo?.directives,
58
- index,
59
- );
60
-
61
- const propNameOrIndex = isNumber(index) ? index : fieldAliasOrName;
62
- const updatedResponseDataPath = buildKey(responseDataPath, propNameOrIndex);
63
-
64
- return {
65
- hashedRequestFieldCacheKey: hashRequest(updatedRequestFieldCacheKey),
66
- propNameOrIndex,
67
- requestFieldCacheKey: updatedRequestFieldCacheKey,
68
- requestFieldPath: updatedRequestFieldPath,
69
- responseDataPath: updatedResponseDataPath,
70
- };
71
- };