@graphql-box/cache-manager 5.2.4 → 5.2.6

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 (43) hide show
  1. package/dist/cjs/index.cjs +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/esm/index.mjs +1 -1
  4. package/dist/esm/index.mjs.map +1 -1
  5. package/dist/production.analysis.txt +62 -33
  6. package/dist/types/cjs/helpers/createEntityDataKey.d.cts +4 -0
  7. package/dist/types/cjs/helpers/createEntityDataKey.d.cts.map +1 -0
  8. package/dist/types/cjs/helpers/filterOutPropsWithEntityArgsOrDirectives.d.cts +5 -0
  9. package/dist/types/cjs/helpers/filterOutPropsWithEntityArgsOrDirectives.d.cts.map +1 -0
  10. package/dist/types/cjs/helpers/filterOutPropsWithEntityOrArgs.d.cts +6 -0
  11. package/dist/types/cjs/helpers/filterOutPropsWithEntityOrArgs.d.cts.map +1 -0
  12. package/dist/types/cjs/helpers/isFieldEntity.d.cts +3 -0
  13. package/dist/types/cjs/helpers/isFieldEntity.d.cts.map +1 -0
  14. package/dist/types/cjs/main.d.cts +0 -2
  15. package/dist/types/cjs/main.d.cts.map +1 -1
  16. package/dist/types/cjs/types.d.cts +2 -2
  17. package/dist/types/cjs/types.d.cts.map +1 -1
  18. package/dist/types/esm/helpers/createEntityDataKey.d.ts +4 -0
  19. package/dist/types/esm/helpers/createEntityDataKey.d.ts.map +1 -0
  20. package/dist/types/esm/helpers/filterOutPropsWithEntityArgsOrDirectives.d.ts +5 -0
  21. package/dist/types/esm/helpers/filterOutPropsWithEntityArgsOrDirectives.d.ts.map +1 -0
  22. package/dist/types/esm/helpers/filterOutPropsWithEntityOrArgs.d.ts +6 -0
  23. package/dist/types/esm/helpers/filterOutPropsWithEntityOrArgs.d.ts.map +1 -0
  24. package/dist/types/esm/helpers/isFieldEntity.d.ts +3 -0
  25. package/dist/types/esm/helpers/isFieldEntity.d.ts.map +1 -0
  26. package/dist/types/esm/main.d.ts +0 -2
  27. package/dist/types/esm/main.d.ts.map +1 -1
  28. package/dist/types/esm/types.d.ts +2 -2
  29. package/dist/types/esm/types.d.ts.map +1 -1
  30. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  31. package/package.json +4 -4
  32. package/src/__snapshots__/index.test.ts.snap +14866 -14866
  33. package/src/helpers/createEntityDataKey.ts +11 -0
  34. package/src/helpers/filterOutPropsWithEntityArgsOrDirectives.ts +45 -0
  35. package/src/helpers/filterOutPropsWithEntityOrArgs.ts +31 -0
  36. package/src/helpers/isFieldEntity.ts +24 -0
  37. package/src/main.ts +79 -113
  38. package/src/types.ts +2 -2
  39. package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts +0 -6
  40. package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts.map +0 -1
  41. package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts +0 -6
  42. package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +0 -1
  43. package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +0 -29
@@ -0,0 +1,11 @@
1
+ import { type EntityData, type FieldTypeInfo } from '@graphql-box/core';
2
+ import { type CacheManagerContext } from '../types.ts';
3
+
4
+ export const createEntityDataKey = (
5
+ fieldData: EntityData,
6
+ fieldTypeInfo: FieldTypeInfo,
7
+ context: CacheManagerContext
8
+ ) => {
9
+ const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
10
+ return `${fieldTypeName}::${String(fieldData[context.typeIDKey!])}`;
11
+ };
@@ -0,0 +1,45 @@
1
+ import { type PlainObject } from '@graphql-box/core';
2
+ import {
3
+ type KeysAndPaths,
4
+ buildFieldKeysAndPaths,
5
+ getName,
6
+ isPlainObject,
7
+ resolveFragments,
8
+ } from '@graphql-box/helpers';
9
+ import { type FieldNode } from 'graphql';
10
+ import { keys } from 'lodash-es';
11
+ import { type CacheManagerContext } from '../types.ts';
12
+ import { isFieldEntity } from './isFieldEntity.ts';
13
+
14
+ export const filterOutPropsWithEntityArgsOrDirectives = (
15
+ fieldData: unknown,
16
+ field: FieldNode,
17
+ ancestorKeysAndPaths: KeysAndPaths,
18
+ context: CacheManagerContext
19
+ ) => {
20
+ if (!isPlainObject(fieldData)) {
21
+ return fieldData;
22
+ }
23
+
24
+ const fieldAndTypeName = resolveFragments(field.selectionSet?.selections, context.fragmentDefinitions);
25
+
26
+ return keys(fieldData).reduce<PlainObject>((acc, key) => {
27
+ const match = fieldAndTypeName.find(({ fieldNode }) => getName(fieldNode) === key);
28
+
29
+ if (match) {
30
+ const keysAndPaths = buildFieldKeysAndPaths(match.fieldNode, ancestorKeysAndPaths, context);
31
+ const fieldTypeInfo = context.fieldTypeMap.get(keysAndPaths.requestFieldPath);
32
+
33
+ if (
34
+ isFieldEntity(fieldData[key], fieldTypeInfo, context.typeIDKey!) ||
35
+ fieldTypeInfo?.hasArguments ||
36
+ fieldTypeInfo?.hasDirectives
37
+ ) {
38
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
39
+ delete fieldData[key];
40
+ }
41
+ }
42
+
43
+ return acc;
44
+ }, fieldData);
45
+ };
@@ -0,0 +1,31 @@
1
+ import { type EntityData } from '@graphql-box/core';
2
+ import { type KeysAndPaths, buildFieldKeysAndPaths, getName, resolveFragments } from '@graphql-box/helpers';
3
+ import { type FieldNode } from 'graphql';
4
+ import { keys } from 'lodash-es';
5
+ import { type CacheManagerContext } from '../types.ts';
6
+ import { isFieldEntity } from './isFieldEntity.ts';
7
+
8
+ export const filterOutPropsWithEntityOrArgs = (
9
+ fieldData: EntityData,
10
+ field: FieldNode,
11
+ ancestorKeysAndPaths: KeysAndPaths,
12
+ context: CacheManagerContext
13
+ ) => {
14
+ const fieldAndTypeName = resolveFragments(field.selectionSet?.selections, context.fragmentDefinitions);
15
+
16
+ return keys(fieldData).reduce<Partial<EntityData>>((acc, key) => {
17
+ const match = fieldAndTypeName.find(({ fieldNode }) => getName(fieldNode) === key);
18
+
19
+ if (match) {
20
+ const { requestFieldPath } = buildFieldKeysAndPaths(match.fieldNode, ancestorKeysAndPaths, context);
21
+ const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
22
+
23
+ if (isFieldEntity(fieldData[key], fieldTypeInfo, context.typeIDKey!) || fieldTypeInfo?.hasArguments) {
24
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
25
+ delete fieldData[key];
26
+ }
27
+ }
28
+
29
+ return acc;
30
+ }, fieldData) as EntityData;
31
+ };
@@ -0,0 +1,24 @@
1
+ import { type EntityData, type FieldTypeInfo } from '@graphql-box/core';
2
+ import { isPlainObject } from '@graphql-box/helpers';
3
+
4
+ export const isFieldEntity = (
5
+ fieldData: unknown,
6
+ fieldTypeInfo: FieldTypeInfo | undefined,
7
+ typeIDKey: string
8
+ ): fieldData is EntityData => {
9
+ if (!isPlainObject(fieldData) || !(typeIDKey in fieldData)) {
10
+ return false;
11
+ }
12
+
13
+ const { isEntity = false, possibleTypes = [] } = fieldTypeInfo ?? {};
14
+
15
+ if (isEntity) {
16
+ return true;
17
+ }
18
+
19
+ if (possibleTypes.length === 0) {
20
+ return false;
21
+ }
22
+
23
+ return possibleTypes.some(type => type.typeName === fieldData.__typename);
24
+ };
package/src/main.ts CHANGED
@@ -36,16 +36,19 @@ import {
36
36
  } from '@graphql-box/helpers';
37
37
  import { Cacheability } from 'cacheability';
38
38
  import { type FieldNode, Kind, OperationTypeNode, print } from 'graphql';
39
- import { assign, cloneDeep, get, isEqual, isNumber, isUndefined, set, unset } from 'lodash-es';
39
+ import { assign, get, isEqual, isNumber, isUndefined, set, unset } from 'lodash-es';
40
40
  import { CACHE_CONTROL, HEADER_NO_CACHE, METADATA, NO_CACHE } from './constants.ts';
41
41
  import { logCacheEntry, logCacheQuery, logPartialCompiled } from './debug/index.ts';
42
42
  import { areOnlyPopulatedFieldsTypeIdKeys } from './helpers/areOnlyPopulatedFieldsTypeIdKeys.ts';
43
43
  import { combineDataSets } from './helpers/combineData.ts';
44
+ import { createEntityDataKey } from './helpers/createEntityDataKey.ts';
44
45
  import { deriveOpCacheability } from './helpers/deriveOpCacheability.ts';
45
- import { filterOutPropsWithArgsOrDirectives } from './helpers/filterOutPropsWithArgsOrDirectives.ts';
46
+ import { filterOutPropsWithEntityArgsOrDirectives } from './helpers/filterOutPropsWithEntityArgsOrDirectives.ts';
47
+ import { filterOutPropsWithEntityOrArgs } from './helpers/filterOutPropsWithEntityOrArgs.ts';
46
48
  import { filterQuery } from './helpers/filterQuery.ts';
47
49
  import { getDataValue } from './helpers/getDataValue.ts';
48
50
  import { hasTypename } from './helpers/hasTypename.ts';
51
+ import { isFieldEntity } from './helpers/isFieldEntity.ts';
49
52
  import { isLastResponseChunk } from './helpers/isLastResponseChunk.ts';
50
53
  import { isNotLastResponseChunk } from './helpers/isNotLastResponseChunk.ts';
51
54
  import { isNotResponseChunk } from './helpers/isNotResponseChunk.ts';
@@ -88,7 +91,7 @@ export class CacheManager implements CacheManagerDef {
88
91
 
89
92
  private static _getFieldDataFromAncestor<T>(ancestorFieldData: unknown, propNameOrIndex: string | number) {
90
93
  const dataValue = getDataValue<T>(ancestorFieldData, propNameOrIndex);
91
- return isObjectLike(dataValue) ? cloneDeep(dataValue) : dataValue;
94
+ return isObjectLike(dataValue) ? structuredClone(dataValue) : dataValue;
92
95
  }
93
96
 
94
97
  private static _getOperationCacheControl(cacheMetadata: CacheMetadata | undefined, operation: string): string {
@@ -584,8 +587,8 @@ export class CacheManager implements CacheManagerDef {
584
587
  requestData,
585
588
  {
586
589
  cacheMetadata,
587
- entityData: cloneDeep(data),
588
- requestFieldPathData: cloneDeep(data),
590
+ entityData: structuredClone(data),
591
+ requestFieldPathData: structuredClone(data),
589
592
  },
590
593
  options,
591
594
  context
@@ -711,22 +714,6 @@ export class CacheManager implements CacheManagerDef {
711
714
  }
712
715
  }
713
716
 
714
- private _isFieldEntity(fieldData: unknown, { isEntity, possibleTypes }: FieldTypeInfo): boolean {
715
- if (!isPlainObject(fieldData) || !(this._typeIDKey in fieldData)) {
716
- return false;
717
- }
718
-
719
- if (isEntity) {
720
- return true;
721
- }
722
-
723
- if (possibleTypes.length === 0) {
724
- return false;
725
- }
726
-
727
- return possibleTypes.some(type => type.typeName === fieldData.__typename);
728
- }
729
-
730
717
  private _mergeResponseData(responseData: PlainData, partialQueryResponse?: PartialQueryResponse): PlainData {
731
718
  if (!partialQueryResponse) {
732
719
  return responseData;
@@ -743,9 +730,10 @@ export class CacheManager implements CacheManagerDef {
743
730
  context: CacheManagerContext
744
731
  ): Promise<void> {
745
732
  const keysAndPaths = buildFieldKeysAndPaths(field, ancestorKeysAndPaths, context);
746
- const { requestFieldCacheKey, requestFieldPath, responseDataPath } = keysAndPaths;
733
+ const { hashedRequestFieldCacheKey, requestFieldCacheKey, requestFieldPath, responseDataPath } = keysAndPaths;
747
734
  const fieldData = get(requestFieldPathData, responseDataPath) as unknown;
748
735
  const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
736
+ const cacheability = cacheMetadata.get(requestFieldPath);
749
737
 
750
738
  if (!isObjectLike(fieldData) && !fieldTypeInfo?.hasDirectives) {
751
739
  return;
@@ -780,13 +768,56 @@ export class CacheManager implements CacheManagerDef {
780
768
  await Promise.all(promises);
781
769
  }
782
770
 
783
- await this._setEntityAndRequestFieldPathCacheEntry(
784
- field,
785
- keysAndPaths,
786
- { cacheMetadata, entityData, requestFieldPathData },
787
- options,
788
- context
789
- );
771
+ if (isUndefined(fieldData) || !fieldTypeInfo || !cacheability) {
772
+ return;
773
+ }
774
+
775
+ const isEntity = isFieldEntity(fieldData, fieldTypeInfo, this._typeIDKey);
776
+ const hasArgsOrDirectives = !!fieldTypeInfo.hasArguments || !!fieldTypeInfo.hasDirectives;
777
+
778
+ if (context.operation === OperationTypeNode.QUERY && (isEntity || hasArgsOrDirectives)) {
779
+ await this._setRequestFieldPathCacheEntry(
780
+ keysAndPaths,
781
+ {
782
+ cacheability,
783
+ fieldData: filterOutPropsWithEntityArgsOrDirectives(structuredClone(fieldData), field, keysAndPaths, context),
784
+ fieldTypeInfo,
785
+ },
786
+ options,
787
+ context
788
+ );
789
+
790
+ if (hasChildFields(field, { fragmentDefinitions: context.fragmentDefinitions })) {
791
+ if (isEntity) {
792
+ set(requestFieldPathData, responseDataPath, {
793
+ __cacheKey: `${REQUEST_FIELD_PATHS}::${hashedRequestFieldCacheKey}`,
794
+ });
795
+ } else {
796
+ unset(requestFieldPathData, responseDataPath);
797
+ }
798
+ }
799
+ }
800
+
801
+ if (isEntity) {
802
+ await this._setEntityCacheEntry(
803
+ {
804
+ cacheability,
805
+ fieldData: filterOutPropsWithEntityOrArgs(
806
+ structuredClone(get(entityData, responseDataPath)) as EntityData,
807
+ field,
808
+ keysAndPaths,
809
+ context
810
+ ),
811
+ fieldTypeInfo,
812
+ },
813
+ options,
814
+ context
815
+ );
816
+
817
+ set(entityData, responseDataPath, {
818
+ __cacheKey: `${DATA_ENTITIES}::${createEntityDataKey(fieldData, fieldTypeInfo, context)}`,
819
+ });
820
+ }
790
821
  }
791
822
 
792
823
  private async _retrieveCachedEntityData(
@@ -943,7 +974,7 @@ export class CacheManager implements CacheManagerDef {
943
974
  _context: CacheManagerContext & { requestFieldCacheKey?: string }
944
975
  ): Promise<void> {
945
976
  try {
946
- await this._cache.set(`${cacheType}::${hash}`, cloneDeep(value), cachemapOptions);
977
+ await this._cache.set(`${cacheType}::${hash}`, structuredClone(value), cachemapOptions);
947
978
  } catch {
948
979
  // no catch
949
980
  }
@@ -980,56 +1011,11 @@ export class CacheManager implements CacheManagerDef {
980
1011
  );
981
1012
  }
982
1013
 
983
- private async _setEntityAndRequestFieldPathCacheEntry(
984
- field: FieldNode,
985
- keysAndPaths: KeysAndPaths,
986
- { cacheMetadata, entityData, requestFieldPathData }: ResponseDataForCaching,
987
- options: RequestOptions,
988
- context: CacheManagerContext
989
- ) {
990
- const { requestFieldPath, responseDataPath } = keysAndPaths;
991
- const fieldData = get(entityData, responseDataPath) as unknown;
992
- const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
993
- const cacheability = cacheMetadata.get(requestFieldPath);
994
-
995
- if (isUndefined(fieldData) || !fieldTypeInfo || !cacheability) {
996
- return;
997
- }
998
-
999
- const promises: Promise<void>[] = [];
1000
-
1001
- promises.push(
1002
- this._setRequestFieldPathCacheEntry(
1003
- field,
1004
- keysAndPaths,
1005
- { cacheability, data: requestFieldPathData, fieldTypeInfo },
1006
- options,
1007
- context
1008
- )
1009
- );
1010
-
1011
- const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
1012
-
1013
- if (!isEntity && fieldTypeInfo.hasArguments) {
1014
- unset(entityData, responseDataPath);
1015
- }
1016
-
1017
- if (isEntity) {
1018
- promises.push(
1019
- this._setEntityCacheEntry(keysAndPaths, { cacheability, data: entityData, fieldTypeInfo }, options, context)
1020
- );
1021
- }
1022
-
1023
- await Promise.all(promises);
1024
- }
1025
-
1026
1014
  private async _setEntityCacheEntry(
1027
- { responseDataPath }: KeysAndPaths,
1028
- { cacheability, data, fieldTypeInfo }: DataForCachingEntry,
1015
+ { cacheability, fieldData, fieldTypeInfo }: DataForCachingEntry<EntityData>,
1029
1016
  options: RequestOptions,
1030
1017
  context: CacheManagerContext
1031
1018
  ) {
1032
- let fieldData = get(data, responseDataPath) as EntityData;
1033
1019
  const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
1034
1020
  const entityDataKey = `${fieldTypeName}::${String(fieldData[this._typeIDKey])}`;
1035
1021
  const result = await this._checkCacheEntry<EntityData>(DATA_ENTITIES, entityDataKey, options, context);
@@ -1046,8 +1032,6 @@ export class CacheManager implements CacheManagerDef {
1046
1032
  options,
1047
1033
  context
1048
1034
  );
1049
-
1050
- set(data, responseDataPath, { __cacheKey: `${DATA_ENTITIES}::${entityDataKey}` });
1051
1035
  }
1052
1036
 
1053
1037
  private _setFieldCacheability(
@@ -1152,48 +1136,30 @@ export class CacheManager implements CacheManagerDef {
1152
1136
  }
1153
1137
 
1154
1138
  private async _setRequestFieldPathCacheEntry(
1155
- field: FieldNode,
1156
1139
  keysAndPaths: KeysAndPaths,
1157
- { cacheability, data, fieldTypeInfo }: DataForCachingEntry,
1140
+ { cacheability, fieldData }: DataForCachingEntry,
1158
1141
  options: RequestOptions,
1159
1142
  context: CacheManagerContext
1160
1143
  ): Promise<void> {
1161
- const { hashedRequestFieldCacheKey, requestFieldCacheKey, responseDataPath } = keysAndPaths;
1162
- let fieldData = get(data, responseDataPath) as unknown;
1163
- const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
1164
- const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
1144
+ const { hashedRequestFieldCacheKey, requestFieldCacheKey } = keysAndPaths;
1165
1145
 
1166
- if (context.operation === OperationTypeNode.QUERY && (isEntity || hasArgsOrDirectives)) {
1167
- if (isPlainObject(fieldData) && field.selectionSet?.selections) {
1168
- fieldData = filterOutPropsWithArgsOrDirectives(fieldData, field.selectionSet.selections, keysAndPaths, context);
1169
- }
1170
-
1171
- const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, {
1172
- ...context,
1173
- requestFieldCacheKey,
1174
- });
1175
-
1176
- if (result && isObjectLike(result.entry) && isObjectLike(fieldData)) {
1177
- fieldData = mergeDataSets(result.entry, fieldData, this._typeIDKey);
1178
- }
1179
-
1180
- await this._setCacheEntry(
1181
- REQUEST_FIELD_PATHS,
1182
- hashedRequestFieldCacheKey,
1183
- fieldData,
1184
- { cacheHeaders: { cacheControl: cacheability.printCacheControl() }, tag: options.tag },
1185
- options,
1186
- { ...context, requestFieldCacheKey }
1187
- );
1146
+ const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, {
1147
+ ...context,
1148
+ requestFieldCacheKey,
1149
+ });
1188
1150
 
1189
- if (hasChildFields(field, { fragmentDefinitions: context.fragmentDefinitions })) {
1190
- if (isEntity) {
1191
- set(data, responseDataPath, { __cacheKey: `${REQUEST_FIELD_PATHS}::${hashedRequestFieldCacheKey}` });
1192
- } else {
1193
- unset(data, responseDataPath);
1194
- }
1195
- }
1151
+ if (result && isObjectLike(result.entry) && isObjectLike(fieldData)) {
1152
+ fieldData = mergeDataSets(result.entry, fieldData, this._typeIDKey);
1196
1153
  }
1154
+
1155
+ void this._setCacheEntry(
1156
+ REQUEST_FIELD_PATHS,
1157
+ hashedRequestFieldCacheKey,
1158
+ fieldData,
1159
+ { cacheHeaders: { cacheControl: cacheability.printCacheControl() }, tag: options.tag },
1160
+ options,
1161
+ { ...context, requestFieldCacheKey }
1162
+ );
1197
1163
  }
1198
1164
 
1199
1165
  private _setResponseChunksAwaitingCaching(
package/src/types.ts CHANGED
@@ -122,9 +122,9 @@ export interface ResponseDataForCaching {
122
122
  requestFieldPathData: PlainData;
123
123
  }
124
124
 
125
- export interface DataForCachingEntry {
125
+ export interface DataForCachingEntry<Data = unknown> {
126
126
  cacheability: Cacheability;
127
- data: PlainData;
127
+ fieldData: Data;
128
128
  fieldTypeInfo: FieldTypeInfo;
129
129
  }
130
130
 
@@ -1,6 +0,0 @@
1
- import { type PlainObject } from '@graphql-box/core';
2
- import { type KeysAndPaths } from '@graphql-box/helpers';
3
- import { type SelectionNode } from 'graphql';
4
- import { type CacheManagerContext } from '../types.cts';
5
- export declare const filterOutPropsWithArgsOrDirectives: (fieldData: PlainObject, selectionNodes: readonly SelectionNode[], ancestorKeysAndPaths: KeysAndPaths, context: CacheManagerContext) => PlainObject;
6
- //# sourceMappingURL=filterOutPropsWithArgsOrDirectives.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filterOutPropsWithArgsOrDirectives.d.cts","sourceRoot":"","sources":["../../../../src/helpers/filterOutPropsWithArgsOrDirectives.cts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,KAAK,YAAY,EAAqD,MAAM,sBAAsB,CAAC;AAC5G,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,kCAAkC,cAClC,WAAW,kBACN,SAAS,aAAa,EAAE,wBAClB,YAAY,WACzB,mBAAmB,gBAkB7B,CAAC"}
@@ -1,6 +0,0 @@
1
- import { type PlainObject } from '@graphql-box/core';
2
- import { type KeysAndPaths } from '@graphql-box/helpers';
3
- import { type SelectionNode } from 'graphql';
4
- import { type CacheManagerContext } from '../types.ts';
5
- export declare const filterOutPropsWithArgsOrDirectives: (fieldData: PlainObject, selectionNodes: readonly SelectionNode[], ancestorKeysAndPaths: KeysAndPaths, context: CacheManagerContext) => PlainObject;
6
- //# sourceMappingURL=filterOutPropsWithArgsOrDirectives.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filterOutPropsWithArgsOrDirectives.d.ts","sourceRoot":"","sources":["../../../../src/helpers/filterOutPropsWithArgsOrDirectives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,KAAK,YAAY,EAAqD,MAAM,sBAAsB,CAAC;AAC5G,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,kCAAkC,cAClC,WAAW,kBACN,SAAS,aAAa,EAAE,wBAClB,YAAY,WACzB,mBAAmB,gBAkB7B,CAAC"}
@@ -1,29 +0,0 @@
1
- import { type PlainObject } from '@graphql-box/core';
2
- import { type KeysAndPaths, buildFieldKeysAndPaths, getName, resolveFragments } from '@graphql-box/helpers';
3
- import { type SelectionNode } from 'graphql';
4
- import { keys } from 'lodash-es';
5
- import { type CacheManagerContext } from '../types.ts';
6
-
7
- export const filterOutPropsWithArgsOrDirectives = (
8
- fieldData: PlainObject,
9
- selectionNodes: readonly SelectionNode[],
10
- ancestorKeysAndPaths: KeysAndPaths,
11
- context: CacheManagerContext
12
- ) => {
13
- const fieldAndTypeName = resolveFragments(selectionNodes, context.fragmentDefinitions);
14
-
15
- return keys(fieldData).reduce<PlainObject>((acc, key) => {
16
- const match = fieldAndTypeName.find(({ fieldNode }) => getName(fieldNode) === key);
17
-
18
- if (match) {
19
- const { requestFieldPath } = buildFieldKeysAndPaths(match.fieldNode, ancestorKeysAndPaths, context);
20
- const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
21
-
22
- if (!fieldTypeInfo?.hasArguments && !fieldTypeInfo?.hasDirectives) {
23
- acc[key] = fieldData[key];
24
- }
25
- }
26
-
27
- return acc;
28
- }, {});
29
- };