@graphql-box/cache-manager 3.1.0 → 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 (82) 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 +45 -57
  4. package/lib/main/helpers/createFragmentSpreadChecklist.js +12 -14
  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 +8 -3
  9. package/lib/main/helpers/filterFragmentDefinitions.js.map +1 -1
  10. package/lib/main/helpers/filterFragmentSpreads.js +0 -1
  11. package/lib/main/helpers/filterFragmentSpreads.js.map +1 -1
  12. package/lib/main/helpers/filterIDsAndTypeNames.js.map +1 -1
  13. package/lib/main/helpers/filterInlineFragments.js.map +1 -1
  14. package/lib/main/helpers/filterOperationAndFragmentDefinitions.js +15 -0
  15. package/lib/main/helpers/filterOperationAndFragmentDefinitions.js.map +1 -0
  16. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js +1 -3
  17. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -1
  18. package/lib/main/helpers/filterQuery.js +6 -7
  19. package/lib/main/helpers/filterQuery.js.map +1 -1
  20. package/lib/main/main/index.js +9 -7
  21. package/lib/main/main/index.js.map +1 -1
  22. package/lib/module/helpers/createFragmentSpreadChecklist.js +12 -13
  23. package/lib/module/helpers/createFragmentSpreadChecklist.js.map +1 -1
  24. package/lib/module/helpers/filterField.js +1 -2
  25. package/lib/module/helpers/filterField.js.map +1 -1
  26. package/lib/module/helpers/filterFragmentDefinitions.js +8 -4
  27. package/lib/module/helpers/filterFragmentDefinitions.js.map +1 -1
  28. package/lib/module/helpers/filterFragmentSpreads.js +0 -1
  29. package/lib/module/helpers/filterFragmentSpreads.js.map +1 -1
  30. package/lib/module/helpers/filterIDsAndTypeNames.js.map +1 -1
  31. package/lib/module/helpers/filterInlineFragments.js.map +1 -1
  32. package/lib/module/helpers/filterOperationAndFragmentDefinitions.js +5 -0
  33. package/lib/module/helpers/filterOperationAndFragmentDefinitions.js.map +1 -0
  34. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js +1 -2
  35. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -1
  36. package/lib/module/helpers/filterQuery.js +6 -6
  37. package/lib/module/helpers/filterQuery.js.map +1 -1
  38. package/lib/module/main/index.js +6 -3
  39. package/lib/module/main/index.js.map +1 -1
  40. package/lib/types/defs/index.d.ts +5 -17
  41. package/lib/types/defs/index.d.ts.map +1 -1
  42. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts +3 -2
  43. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts.map +1 -1
  44. package/lib/types/helpers/filterField.d.ts +2 -2
  45. package/lib/types/helpers/filterField.d.ts.map +1 -1
  46. package/lib/types/helpers/filterFragmentDefinitions.d.ts +1 -5
  47. package/lib/types/helpers/filterFragmentDefinitions.d.ts.map +1 -1
  48. package/lib/types/helpers/filterFragmentSpreads.d.ts +2 -2
  49. package/lib/types/helpers/filterFragmentSpreads.d.ts.map +1 -1
  50. package/lib/types/helpers/filterIDsAndTypeNames.d.ts +2 -2
  51. package/lib/types/helpers/filterIDsAndTypeNames.d.ts.map +1 -1
  52. package/lib/types/helpers/filterInlineFragments.d.ts +2 -2
  53. package/lib/types/helpers/filterInlineFragments.d.ts.map +1 -1
  54. package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts +4 -0
  55. package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts.map +1 -0
  56. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts +2 -1
  57. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +1 -1
  58. package/lib/types/helpers/filterQuery.d.ts +1 -1
  59. package/lib/types/helpers/filterQuery.d.ts.map +1 -1
  60. package/lib/types/main/index.d.ts +3 -2
  61. package/lib/types/main/index.d.ts.map +1 -1
  62. package/package.json +1 -1
  63. package/src/__snapshots__/index.test.ts.snap +25475 -0
  64. package/src/defs/index.ts +10 -18
  65. package/src/helpers/createFragmentSpreadChecklist.ts +5 -5
  66. package/src/helpers/filterField.ts +10 -4
  67. package/src/helpers/filterFragmentDefinitions.ts +6 -2
  68. package/src/helpers/filterFragmentSpreads.ts +2 -3
  69. package/src/helpers/filterIDsAndTypeNames.ts +5 -2
  70. package/src/helpers/filterInlineFragments.ts +5 -2
  71. package/src/helpers/filterOperationAndFragmentDefinitions.ts +10 -0
  72. package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +2 -3
  73. package/src/helpers/filterQuery.ts +9 -4
  74. package/src/index.test.ts +52 -0
  75. package/src/main/index.ts +13 -4
  76. package/lib/main/helpers/buildKeysAndPaths.js +0 -73
  77. package/lib/main/helpers/buildKeysAndPaths.js.map +0 -1
  78. package/lib/module/helpers/buildKeysAndPaths.js +0 -54
  79. package/lib/module/helpers/buildKeysAndPaths.js.map +0 -1
  80. package/lib/types/helpers/buildKeysAndPaths.d.ts +0 -10
  81. package/lib/types/helpers/buildKeysAndPaths.d.ts.map +0 -1
  82. package/src/helpers/buildKeysAndPaths.ts +0 -71
package/src/defs/index.ts CHANGED
@@ -1,9 +1,11 @@
1
- import Cachemap, { CacheHeaders, Metadata } from "@cachemap/core";
1
+ import Cachemap, { CacheHeaders } from "@cachemap/core";
2
+ import { Metadata } from "@cachemap/types";
2
3
  import {
3
4
  CacheMetadata,
4
5
  CacheTypes,
5
6
  DehydratedCacheMetadata,
6
7
  FieldTypeInfo,
8
+ FragmentDefinitionNodeMap,
7
9
  PlainObjectMap,
8
10
  PlainObjectStringMap,
9
11
  RawResponseDataWithMaybeCacheMetadata,
@@ -12,7 +14,6 @@ import {
12
14
  RequestOptions,
13
15
  ResponseData,
14
16
  } from "@graphql-box/core";
15
- import { FragmentDefinitionNodeMap } from "@graphql-box/helpers";
16
17
  import Cacheability from "cacheability";
17
18
 
18
19
  export interface UserOptions {
@@ -117,21 +118,6 @@ export interface CachedAncestorFieldData {
117
118
  typeName?: string;
118
119
  }
119
120
 
120
- export interface KeysAndPathsOptions {
121
- index?: number;
122
- requestFieldCacheKey?: string;
123
- requestFieldPath?: string;
124
- responseDataPath?: string;
125
- }
126
-
127
- export interface KeysAndPaths {
128
- hashedRequestFieldCacheKey: string;
129
- propNameOrIndex: string | number;
130
- requestFieldCacheKey: string;
131
- requestFieldPath: string;
132
- responseDataPath: string;
133
- }
134
-
135
121
  export interface TypeNamesAndKind {
136
122
  dataTypeName: string | undefined;
137
123
  fieldTypeName: string | undefined;
@@ -183,7 +169,7 @@ export interface CacheManagerDef {
183
169
  analyzeQuery(requestData: RequestData, options: RequestOptions, context: RequestContext): Promise<AnalyzeQueryResult>;
184
170
  cacheQuery(
185
171
  requestData: RequestData,
186
- updatedRequestData: RequestData,
172
+ updatedRequestData: RequestData | undefined,
187
173
  responseData: RawResponseDataWithMaybeCacheMetadata,
188
174
  options: RequestOptions,
189
175
  context: RequestContext,
@@ -206,6 +192,12 @@ export interface CacheManagerDef {
206
192
  context: RequestContext,
207
193
  ): Promise<ResponseData | false>;
208
194
  deletePartialQueryResponse(hash: string): void;
195
+ setQueryResponseCacheEntry(
196
+ requestData: RequestData,
197
+ responseData: ResponseData,
198
+ options: RequestOptions,
199
+ context: CacheManagerContext,
200
+ ): Promise<void>;
209
201
  }
210
202
 
211
203
  export type CacheManagerInit = (options: ClientOptions) => CacheManagerDef;
@@ -1,6 +1,6 @@
1
- import { getFragmentDefinitions } from "@graphql-box/helpers";
2
- import { DocumentNode } from "graphql";
1
+ import { RequestData } from "@graphql-box/core";
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: DocumentNode) =>
14
- keys(getFragmentDefinitions(ast) ?? {}).reduce((acc: FragmentSpreadCheckist, name) => {
15
- acc[name] = { deleted: 0, paths: [], total: 0 };
13
+ export default ({ request }: RequestData, { fragmentDefinitions }: CacheManagerContext) =>
14
+ keys(fragmentDefinitions ?? {}).reduce((acc: FragmentSpreadCheckist, name) => {
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";
3
- import { FieldNode, FragmentDefinitionNode } from "graphql";
2
+ import {
3
+ FRAGMENT_SPREAD,
4
+ buildFieldKeysAndPaths,
5
+ deleteChildFields,
6
+ getChildFields,
7
+ getName,
8
+ hasChildFields,
9
+ } from "@graphql-box/helpers";
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";
@@ -10,7 +16,7 @@ import filterIDsAndTypeNames from "./filterIDsAndTypeNames";
10
16
  import filterInlineFragments from "./filterInlineFragments";
11
17
 
12
18
  const filterField = (
13
- field: FieldNode | FragmentDefinitionNode,
19
+ field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
14
20
  fieldPathChecklist: FieldPathChecklist,
15
21
  fragmentSpreadChecklist: FragmentSpreadCheckist,
16
22
  ancestorRequestFieldPath: string,
@@ -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];
@@ -34,6 +34,10 @@ export default (
34
34
  return deleted > 0 && deleted === total ? [...names, key] : names;
35
35
  }, []);
36
36
 
37
+ if (!definitionsToDelete.length) {
38
+ return ast;
39
+ }
40
+
37
41
  return deleteFragmentDefinitions(ast, {
38
42
  include: definitionsToDelete,
39
43
  });
@@ -1,11 +1,11 @@
1
1
  import { deleteFragmentSpreads } from "@graphql-box/helpers";
2
- import { FieldNode, FragmentDefinitionNode } from "graphql";
2
+ import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
3
3
  import { isEmpty, keys } from "lodash";
4
4
  import { FragmentSpreadFieldCounter } from "../defs";
5
5
  import { FragmentSpreadCheckist } from "./createFragmentSpreadChecklist";
6
6
 
7
7
  export default (
8
- field: FieldNode | FragmentDefinitionNode,
8
+ field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
9
9
  fragmentSpreadFieldCounter: FragmentSpreadFieldCounter,
10
10
  fragmentSpreadChecklist: FragmentSpreadCheckist,
11
11
  ancestorRequestFieldPath: string,
@@ -15,7 +15,6 @@ export default (
15
15
  }
16
16
 
17
17
  keys(fragmentSpreadFieldCounter).forEach(key => {
18
- fragmentSpreadChecklist[key].total += 1;
19
18
  fragmentSpreadChecklist[key].paths.push(ancestorRequestFieldPath);
20
19
 
21
20
  const { hasData, total } = fragmentSpreadFieldCounter[key];
@@ -1,9 +1,12 @@
1
1
  import { TYPE_NAME_KEY } from "@graphql-box/core";
2
2
  import { deleteChildFields, getChildFields, getName } from "@graphql-box/helpers";
3
- import { FieldNode, FragmentDefinitionNode } from "graphql";
3
+ import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
4
4
  import { CacheManagerContext } from "../defs";
5
5
 
6
- export default (field: FieldNode | FragmentDefinitionNode, { fragmentDefinitions, typeIDKey }: CacheManagerContext) => {
6
+ export default (
7
+ field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
8
+ { fragmentDefinitions, typeIDKey }: CacheManagerContext,
9
+ ) => {
7
10
  const fieldsAndTypeNames = getChildFields(field, { fragmentDefinitions });
8
11
 
9
12
  if (!fieldsAndTypeNames || fieldsAndTypeNames.length > 3) {
@@ -1,8 +1,11 @@
1
1
  import { deleteInlineFragments, getChildFields, getInlineFragments, getName } from "@graphql-box/helpers";
2
- import { FieldNode, FragmentDefinitionNode } from "graphql";
2
+ import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
3
3
  import { CacheManagerContext } from "..";
4
4
 
5
- export default (field: FieldNode | FragmentDefinitionNode, { fragmentDefinitions, typeIDKey }: CacheManagerContext) => {
5
+ export default (
6
+ field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
7
+ { fragmentDefinitions, typeIDKey }: CacheManagerContext,
8
+ ) => {
6
9
  const inlineFragments = getInlineFragments(field);
7
10
  let filtered = false;
8
11
 
@@ -0,0 +1,10 @@
1
+ import { FRAGMENT_DEFINITION, OPERATION_DEFINITION, isKind } from "@graphql-box/helpers";
2
+ import { DocumentNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
3
+
4
+ export default (ast: DocumentNode) => {
5
+ return ast.definitions.filter(
6
+ definition =>
7
+ isKind<OperationDefinitionNode>(definition, OPERATION_DEFINITION) ||
8
+ isKind<FragmentDefinitionNode>(definition, FRAGMENT_DEFINITION),
9
+ ) as (OperationDefinitionNode | FragmentDefinitionNode)[];
10
+ };
@@ -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,12 +1,17 @@
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";
8
12
 
9
- export default ({ ast }: RequestData, { fieldPathChecklist }: CachedResponseData, context: CacheManagerContext) => {
13
+ export default (requestData: RequestData, { fieldPathChecklist }: CachedResponseData, context: CacheManagerContext) => {
14
+ const { ast } = requestData;
10
15
  const queryNode = getOperationDefinitions(ast, context.operation)[0];
11
16
  const { fragmentDefinitions } = context;
12
17
  const fieldsAndTypeNames = getChildFields(queryNode, { fragmentDefinitions });
@@ -15,7 +20,7 @@ export default ({ ast }: RequestData, { fieldPathChecklist }: CachedResponseData
15
20
  return ast;
16
21
  }
17
22
 
18
- const fragmentSpreadChecklist = createFragmentSpreadChecklist(ast);
23
+ const fragmentSpreadChecklist = createFragmentSpreadChecklist(requestData, context);
19
24
 
20
25
  for (let i = fieldsAndTypeNames.length - 1; i >= 0; i -= 1) {
21
26
  const { fieldNode } = fieldsAndTypeNames[i];
package/src/index.test.ts CHANGED
@@ -1312,6 +1312,58 @@ describe("@graphql-box/cache-manager >>", () => {
1312
1312
  });
1313
1313
  });
1314
1314
 
1315
+ describe("fragment spreads >> within fragment spreads >>", () => {
1316
+ beforeAll(async () => {
1317
+ analyzeQueryResult = undefined;
1318
+ // @ts-ignore
1319
+ jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
1320
+
1321
+ cacheManager = new CacheManager({
1322
+ cache: new Cachemap({
1323
+ name: "cachemap",
1324
+ store: map(),
1325
+ type: "someType",
1326
+ }),
1327
+ cascadeCacheControl: true,
1328
+ typeIDKey: DEFAULT_TYPE_ID_KEY,
1329
+ });
1330
+
1331
+ const requestData = getRequestData(parsedRequests.getSearchResultsQuery);
1332
+
1333
+ await cacheManager.cacheQuery(
1334
+ requestData,
1335
+ requestData,
1336
+ responses.getSearchResultsQuery,
1337
+ { awaitDataCaching: true },
1338
+ getRequestContext({ fieldTypeMap: requestFieldTypeMaps.getSearchResultsQuery, hasDeferOrStream: true }),
1339
+ );
1340
+
1341
+ analyzeQueryResult = await cacheManager.analyzeQuery(
1342
+ getRequestData(parsedRequests.getMoviePreviewQuery),
1343
+ { awaitDataCaching: true },
1344
+ getRequestContext({ fieldTypeMap: requestFieldTypeMaps.getMoviePreviewQuery, hasDeferOrStream: true }),
1345
+ );
1346
+ });
1347
+
1348
+ it("correct request data", () => {
1349
+ const { ast, ...otherProps } = analyzeQueryResult?.updated as RequestData;
1350
+ expect(otherProps).toMatchSnapshot();
1351
+ });
1352
+
1353
+ it("no response data", () => {
1354
+ expect(analyzeQueryResult?.response).toBeUndefined();
1355
+ });
1356
+
1357
+ it("correct cache data", async () => {
1358
+ expect(await cacheManager.cache.export()).toMatchSnapshot();
1359
+ });
1360
+
1361
+ it("correct partial data", () => {
1362
+ // @ts-ignore
1363
+ expect(cacheManager._partialQueryResponses).toMatchSnapshot();
1364
+ });
1365
+ });
1366
+
1315
1367
  describe("defer >>", () => {
1316
1368
  beforeAll(async () => {
1317
1369
  analyzeQueryResult = undefined;
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,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
- };