@graphql-box/cache-manager 3.1.2 → 3.2.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.
Files changed (65) 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 +44 -56
  4. package/lib/main/debug/log-cache-entry/index.js +8 -3
  5. package/lib/main/debug/log-cache-entry/index.js.map +1 -1
  6. package/lib/main/debug/log-cache-query/index.js +8 -3
  7. package/lib/main/debug/log-cache-query/index.js.map +1 -1
  8. package/lib/main/helpers/createFragmentSpreadChecklist.js +10 -15
  9. package/lib/main/helpers/createFragmentSpreadChecklist.js.map +1 -1
  10. package/lib/main/helpers/filterField.js +1 -3
  11. package/lib/main/helpers/filterField.js.map +1 -1
  12. package/lib/main/helpers/filterFragmentDefinitions.js +3 -3
  13. package/lib/main/helpers/filterFragmentDefinitions.js.map +1 -1
  14. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js +1 -3
  15. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -1
  16. package/lib/main/helpers/filterQuery.js +2 -4
  17. package/lib/main/helpers/filterQuery.js.map +1 -1
  18. package/lib/main/main/index.js +25 -14
  19. package/lib/main/main/index.js.map +1 -1
  20. package/lib/module/debug/log-cache-entry/index.js +8 -3
  21. package/lib/module/debug/log-cache-entry/index.js.map +1 -1
  22. package/lib/module/debug/log-cache-query/index.js +8 -3
  23. package/lib/module/debug/log-cache-query/index.js.map +1 -1
  24. package/lib/module/helpers/createFragmentSpreadChecklist.js +10 -14
  25. package/lib/module/helpers/createFragmentSpreadChecklist.js.map +1 -1
  26. package/lib/module/helpers/filterField.js +1 -2
  27. package/lib/module/helpers/filterField.js.map +1 -1
  28. package/lib/module/helpers/filterFragmentDefinitions.js +4 -4
  29. package/lib/module/helpers/filterFragmentDefinitions.js.map +1 -1
  30. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js +1 -2
  31. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -1
  32. package/lib/module/helpers/filterQuery.js +2 -3
  33. package/lib/module/helpers/filterQuery.js.map +1 -1
  34. package/lib/module/main/index.js +22 -10
  35. package/lib/module/main/index.js.map +1 -1
  36. package/lib/types/debug/log-cache-entry/index.d.ts.map +1 -1
  37. package/lib/types/debug/log-cache-query/index.d.ts.map +1 -1
  38. package/lib/types/defs/index.d.ts +3 -16
  39. package/lib/types/defs/index.d.ts.map +1 -1
  40. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts +2 -1
  41. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts.map +1 -1
  42. package/lib/types/helpers/filterField.d.ts.map +1 -1
  43. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts +2 -1
  44. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +1 -1
  45. package/lib/types/helpers/filterQuery.d.ts.map +1 -1
  46. package/lib/types/main/index.d.ts +6 -3
  47. package/lib/types/main/index.d.ts.map +1 -1
  48. package/package.json +1 -1
  49. package/src/__snapshots__/index.test.ts.snap +1082 -1082
  50. package/src/debug/log-cache-entry/index.ts +8 -3
  51. package/src/debug/log-cache-query/index.ts +8 -3
  52. package/src/defs/index.ts +8 -17
  53. package/src/helpers/createFragmentSpreadChecklist.ts +3 -3
  54. package/src/helpers/filterField.ts +8 -2
  55. package/src/helpers/filterFragmentDefinitions.ts +2 -2
  56. package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +2 -3
  57. package/src/helpers/filterQuery.ts +7 -3
  58. package/src/main/index.ts +30 -14
  59. package/lib/main/helpers/buildKeysAndPaths.js +0 -73
  60. package/lib/main/helpers/buildKeysAndPaths.js.map +0 -1
  61. package/lib/module/helpers/buildKeysAndPaths.js +0 -54
  62. package/lib/module/helpers/buildKeysAndPaths.js.map +0 -1
  63. package/lib/types/helpers/buildKeysAndPaths.d.ts +0 -10
  64. package/lib/types/helpers/buildKeysAndPaths.d.ts.map +0 -1
  65. package/src/helpers/buildKeysAndPaths.ts +0 -71
@@ -12,7 +12,9 @@ export default function logCacheEntry() {
12
12
 
13
13
  descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {
14
14
  return new Promise<void>(async resolve => {
15
- const { debugManager, ...otherContext } = args[5] as RequestContext;
15
+ const { debugManager, requestFieldCacheKey, ...otherContext } = args[5] as RequestContext & {
16
+ requestFieldCacheKey?: string;
17
+ };
16
18
 
17
19
  if (!debugManager) {
18
20
  await method.apply(this, args);
@@ -26,7 +28,7 @@ export default function logCacheEntry() {
26
28
  const duration = endTime - startTime;
27
29
  resolve();
28
30
 
29
- debugManager.emit(CACHE_ENTRY_ADDED, {
31
+ const payload = {
30
32
  cachemapOptions: args[3],
31
33
  cacheType: args[0],
32
34
  context: otherContext,
@@ -34,7 +36,10 @@ export default function logCacheEntry() {
34
36
  options: args[4],
35
37
  stats: { duration, endTime, startTime },
36
38
  value: args[2],
37
- });
39
+ ...(requestFieldCacheKey ? { decryptedCacheKey: requestFieldCacheKey } : {}),
40
+ };
41
+
42
+ debugManager.emit(CACHE_ENTRY_ADDED, payload);
38
43
  });
39
44
  };
40
45
  };
@@ -13,7 +13,9 @@ export default function logCacheQuery() {
13
13
  descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {
14
14
  try {
15
15
  return new Promise(async resolve => {
16
- const { debugManager, ...otherContext } = args[3] as RequestContext;
16
+ const { debugManager, requestFieldCacheKey, ...otherContext } = args[3] as RequestContext & {
17
+ requestFieldCacheKey?: string;
18
+ };
17
19
 
18
20
  if (!debugManager) {
19
21
  resolve(await method.apply(this, args));
@@ -26,14 +28,17 @@ export default function logCacheQuery() {
26
28
  const duration = endTime - startTime;
27
29
  resolve(result);
28
30
 
29
- debugManager.emit(CACHE_ENTRY_QUERIED, {
31
+ const payload = {
30
32
  cacheType: args[0],
31
33
  context: otherContext,
32
34
  hash: args[1],
33
35
  options: args[2],
34
36
  result,
35
37
  stats: { duration, endTime, startTime },
36
- });
38
+ ...(requestFieldCacheKey ? { decryptedCacheKey: requestFieldCacheKey } : {}),
39
+ };
40
+
41
+ debugManager.emit(CACHE_ENTRY_QUERIED, payload);
37
42
  });
38
43
  } catch (error) {
39
44
  return Promise.reject(error);
package/src/defs/index.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  CacheTypes,
6
6
  DehydratedCacheMetadata,
7
7
  FieldTypeInfo,
8
+ FragmentDefinitionNodeMap,
8
9
  PlainObjectMap,
9
10
  PlainObjectStringMap,
10
11
  RawResponseDataWithMaybeCacheMetadata,
@@ -13,7 +14,6 @@ import {
13
14
  RequestOptions,
14
15
  ResponseData,
15
16
  } from "@graphql-box/core";
16
- import { FragmentDefinitionNodeMap } from "@graphql-box/helpers";
17
17
  import Cacheability from "cacheability";
18
18
 
19
19
  export interface UserOptions {
@@ -118,21 +118,6 @@ export interface CachedAncestorFieldData {
118
118
  typeName?: string;
119
119
  }
120
120
 
121
- export interface KeysAndPathsOptions {
122
- index?: number;
123
- requestFieldCacheKey?: string;
124
- requestFieldPath?: string;
125
- responseDataPath?: string;
126
- }
127
-
128
- export interface KeysAndPaths {
129
- hashedRequestFieldCacheKey: string;
130
- propNameOrIndex: string | number;
131
- requestFieldCacheKey: string;
132
- requestFieldPath: string;
133
- responseDataPath: string;
134
- }
135
-
136
121
  export interface TypeNamesAndKind {
137
122
  dataTypeName: string | undefined;
138
123
  fieldTypeName: string | undefined;
@@ -184,7 +169,7 @@ export interface CacheManagerDef {
184
169
  analyzeQuery(requestData: RequestData, options: RequestOptions, context: RequestContext): Promise<AnalyzeQueryResult>;
185
170
  cacheQuery(
186
171
  requestData: RequestData,
187
- updatedRequestData: RequestData,
172
+ updatedRequestData: RequestData | undefined,
188
173
  responseData: RawResponseDataWithMaybeCacheMetadata,
189
174
  options: RequestOptions,
190
175
  context: RequestContext,
@@ -207,6 +192,12 @@ export interface CacheManagerDef {
207
192
  context: RequestContext,
208
193
  ): Promise<ResponseData | false>;
209
194
  deletePartialQueryResponse(hash: string): void;
195
+ setQueryResponseCacheEntry(
196
+ requestData: RequestData,
197
+ responseData: ResponseData,
198
+ options: RequestOptions,
199
+ context: CacheManagerContext,
200
+ ): Promise<void>;
210
201
  }
211
202
 
212
203
  export type CacheManagerInit = (options: ClientOptions) => CacheManagerDef;
@@ -1,6 +1,6 @@
1
1
  import { RequestData } from "@graphql-box/core";
2
- import { getFragmentDefinitions } from "@graphql-box/helpers";
3
2
  import { keys } from "lodash";
3
+ import { CacheManagerContext } from "../defs";
4
4
 
5
5
  export type FragmentSpreadCheckist = {
6
6
  [key: string]: {
@@ -10,8 +10,8 @@ export type FragmentSpreadCheckist = {
10
10
  };
11
11
  };
12
12
 
13
- export default ({ ast, request }: RequestData) =>
14
- keys(getFragmentDefinitions(ast) ?? {}).reduce((acc: FragmentSpreadCheckist, name) => {
13
+ export default ({ request }: RequestData, { fragmentDefinitions }: CacheManagerContext) =>
14
+ keys(fragmentDefinitions ?? {}).reduce((acc: FragmentSpreadCheckist, name) => {
15
15
  acc[name] = { deleted: 0, paths: [], total: (request.match(new RegExp(`\\.\\.\\.${name}`, "g")) || []).length };
16
16
  return acc;
17
17
  }, {});
@@ -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
 
@@ -317,7 +317,7 @@ export class CacheManager implements CacheManagerDef {
317
317
  cacheType: CacheTypes,
318
318
  hash: string,
319
319
  options: RequestOptions,
320
- context: RequestContext,
320
+ context: RequestContext & { requestFieldCacheKey?: string },
321
321
  ): Promise<CheckCacheEntryResult | false> {
322
322
  return this._checkCacheEntry(cacheType, hash, options, context);
323
323
  }
@@ -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,
@@ -367,7 +376,7 @@ export class CacheManager implements CacheManagerDef {
367
376
  context: CacheManagerContext,
368
377
  ): Promise<void> {
369
378
  const keysAndPaths = buildFieldKeysAndPaths(fieldNode, cachedAncestorFieldData, context);
370
- const { hashedRequestFieldCacheKey, propNameOrIndex, requestFieldPath } = keysAndPaths;
379
+ const { hashedRequestFieldCacheKey, propNameOrIndex, requestFieldCacheKey, requestFieldPath } = keysAndPaths;
371
380
  const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
372
381
  const { entityData, fragmentKind, fragmentName, requestFieldPathData, typeName } = cachedAncestorFieldData;
373
382
 
@@ -381,6 +390,7 @@ export class CacheManager implements CacheManagerDef {
381
390
  if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
382
391
  const { cacheability, entry } = await this._retrieveCachedRequestFieldPathData(
383
392
  hashedRequestFieldCacheKey,
393
+ requestFieldCacheKey,
384
394
  options,
385
395
  context,
386
396
  );
@@ -600,7 +610,7 @@ export class CacheManager implements CacheManagerDef {
600
610
  cacheType: CacheTypes,
601
611
  hash: string,
602
612
  options: RequestOptions,
603
- context: CacheManagerContext,
613
+ context: CacheManagerContext & { requestFieldCacheKey?: string },
604
614
  ): Promise<CheckCacheEntryResult | false> {
605
615
  try {
606
616
  const cacheability = await this._hasCacheEntry(cacheType, hash);
@@ -647,7 +657,7 @@ export class CacheManager implements CacheManagerDef {
647
657
  cacheType: CacheTypes,
648
658
  hash: string,
649
659
  _options: RequestOptions,
650
- _context: CacheManagerContext,
660
+ _context: CacheManagerContext & { requestFieldCacheKey?: string },
651
661
  ): Promise<any> {
652
662
  try {
653
663
  return await this._cache.get(`${cacheType}::${hash}`);
@@ -788,7 +798,7 @@ export class CacheManager implements CacheManagerDef {
788
798
 
789
799
  private async _retrieveCachedParentNodeData(
790
800
  { entityData: ancestorEntityData, requestFieldPathData: ancestorRequestFieldPathData }: CachedAncestorFieldData,
791
- { hashedRequestFieldCacheKey, propNameOrIndex }: KeysAndPaths,
801
+ { hashedRequestFieldCacheKey, propNameOrIndex, requestFieldCacheKey }: KeysAndPaths,
792
802
  fieldTypeInfo: FieldTypeInfo,
793
803
  options: RequestOptions,
794
804
  context: CacheManagerContext,
@@ -800,6 +810,7 @@ export class CacheManager implements CacheManagerDef {
800
810
  if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
801
811
  const { cacheability: entryCacheability, entry } = await this._retrieveCachedRequestFieldPathData(
802
812
  hashedRequestFieldCacheKey,
813
+ requestFieldCacheKey,
803
814
  options,
804
815
  context,
805
816
  );
@@ -847,10 +858,12 @@ export class CacheManager implements CacheManagerDef {
847
858
 
848
859
  private async _retrieveCachedRequestFieldPathData(
849
860
  hash: string,
861
+ requestFieldCacheKey: string,
850
862
  options: RequestOptions,
851
863
  context: CacheManagerContext,
852
864
  ) {
853
- return (this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, context) || {}) as Partial<CheckCacheEntryResult>;
865
+ return (this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, { ...context, requestFieldCacheKey }) ||
866
+ {}) as Partial<CheckCacheEntryResult>;
854
867
  }
855
868
 
856
869
  private async _retrieveCachedResponseData(
@@ -907,7 +920,7 @@ export class CacheManager implements CacheManagerDef {
907
920
  value: any,
908
921
  cachemapOptions: CachemapOptions,
909
922
  _options: RequestOptions,
910
- _context: CacheManagerContext,
923
+ _context: CacheManagerContext & { requestFieldCacheKey?: string },
911
924
  ): Promise<void> {
912
925
  try {
913
926
  await this._cache.set(`${cacheType}::${hash}`, cloneDeep(value), cachemapOptions);
@@ -1115,7 +1128,7 @@ export class CacheManager implements CacheManagerDef {
1115
1128
  options: RequestOptions,
1116
1129
  context: CacheManagerContext,
1117
1130
  ): Promise<void> {
1118
- const { hashedRequestFieldCacheKey, responseDataPath } = keysAndPaths;
1131
+ const { hashedRequestFieldCacheKey, requestFieldCacheKey, responseDataPath } = keysAndPaths;
1119
1132
  let fieldData = get(data, responseDataPath);
1120
1133
  const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
1121
1134
  const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
@@ -1125,7 +1138,10 @@ export class CacheManager implements CacheManagerDef {
1125
1138
  fieldData = filterOutPropsWithArgsOrDirectives(fieldData, field.selectionSet.selections, keysAndPaths, context);
1126
1139
  }
1127
1140
 
1128
- const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, context);
1141
+ const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, {
1142
+ ...context,
1143
+ requestFieldCacheKey,
1144
+ });
1129
1145
 
1130
1146
  if (result && isObjectLike(fieldData)) {
1131
1147
  fieldData = this._mergeObjects(result.entry, fieldData);
@@ -1137,7 +1153,7 @@ export class CacheManager implements CacheManagerDef {
1137
1153
  fieldData,
1138
1154
  { cacheHeaders: { cacheControl: cacheability.printCacheControl() }, tag: options.tag },
1139
1155
  options,
1140
- context,
1156
+ { ...context, requestFieldCacheKey },
1141
1157
  );
1142
1158
 
1143
1159
  if (hasChildFields(field, { fragmentDefinitions: context.fragmentDefinitions })) {
@@ -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,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;;;;AAWA,MAAMC,yBAAyB,GAAG,CACvCC,IADuC,EAEvCC,oBAFuC,EAGvCC,IAHuC,EAIvCC,UAJuC,EAKvCC,KALuC,KAMpC;AAAA;;AACH,MAAIV,GAAG,GAAI,GAAE,wBAASU,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,CAAeV,IAAf,CAAoB,GAApB,CAAyB,EAAzC;AACD;;AAED,SAAON,QAAQ,CAACS,oBAAD,EAAuBP,GAAvB,CAAf;AACD,CAtBM;;;;AAwBA,MAAMe,sBAAsB,GAAG,CACpCC,KADoC,EAEpCC,OAFoC,EAGpCC,OAHoC,KAInB;AACjB,QAAMZ,IAAI,GAAG,sBAAQU,KAAR,CAAb;AACA,QAAM;AAAEN,IAAAA,KAAF;AAASH,IAAAA,oBAAoB,GAAG,EAAhC;AAAoCY,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,CAAeV,IAAf,CAAoB,GAApB,CAAyB,EAAzC;AACD;;AAED,SAAON,QAAQ,CAACS,oBAAD,EAAuBP,GAAvB,CAAf;AACD,CAtBM;AAwBP,OAAO,MAAMe,sBAAsB,GAAG,CACpCC,KADoC,EAEpCC,OAFoC,EAGpCC,OAHoC,KAInB;AACjB,QAAMZ,IAAI,GAAGV,OAAO,CAACoB,KAAD,CAApB;AACA,QAAM;AAAEN,IAAAA,KAAF;AAASH,IAAAA,oBAAoB,GAAG,EAAhC;AAAoCY,IAAAA,gBAAgB,GAAG,EAAvD;AAA2DC,IAAAA,gBAAgB,GAAG;AAA9E,MAAqFH,OAA3F;AACA,QAAMI,gBAAgB,GAAG3B,QAAQ,CAACsB,KAAD,CAAR,IAAmBV,IAA5C;AACA,QAAMgB,uBAAuB,GAAG,UAASZ,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,EAG3DZ,YAAY,CAACqB,KAAD,CAH+C,EAI3DO,aAJ2D,aAI3DA,aAJ2D,uBAI3DA,aAAa,CAAEd,UAJ4C,EAK3DC,KAL2D,CAA7D;AAQA,QAAMiB,eAAe,GAAG,UAASjB,KAAT,IAAkBA,KAAlB,GAA0BW,gBAAlD;AACA,QAAMO,uBAAuB,GAAG9B,QAAQ,CAACsB,gBAAD,EAAmBO,eAAnB,CAAxC;AAEA,SAAO;AACLE,IAAAA,0BAA0B,EAAEhC,WAAW,CAAC6B,2BAAD,CADlC;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,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
- };