@graphql-box/cache-manager 4.1.4 → 5.0.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.
- package/README.md +1 -5
- package/dist/cjs/index.cjs +1477 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/{lib/module/main/index.js → dist/esm/index.mjs} +734 -331
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/cjs/constants.d.cts +6 -0
- package/dist/types/cjs/constants.d.cts.map +1 -0
- package/dist/types/cjs/debug/index.d.cts +4 -0
- package/dist/types/cjs/debug/index.d.cts.map +1 -0
- package/dist/types/cjs/debug/logCacheEntry.d.cts +8 -0
- package/dist/types/cjs/debug/logCacheEntry.d.cts.map +1 -0
- package/dist/types/cjs/debug/logCacheQuery.d.cts +8 -0
- package/dist/types/cjs/debug/logCacheQuery.d.cts.map +1 -0
- package/dist/types/cjs/debug/logPartialCompiled.d.cts +6 -0
- package/dist/types/cjs/debug/logPartialCompiled.d.cts.map +1 -0
- package/dist/types/cjs/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.cts +3 -0
- package/dist/types/cjs/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.cts.map +1 -0
- package/dist/types/cjs/helpers/checkFieldPathChecklist.d.cts +3 -0
- package/dist/types/cjs/helpers/checkFieldPathChecklist.d.cts.map +1 -0
- package/dist/types/cjs/helpers/combineData.d.cts +2 -0
- package/dist/types/cjs/helpers/combineData.d.cts.map +1 -0
- package/dist/types/cjs/helpers/createFragmentSpreadChecklist.d.cts +9 -0
- package/dist/types/cjs/helpers/createFragmentSpreadChecklist.d.cts.map +1 -0
- package/dist/types/cjs/helpers/deriveOpCacheability.d.cts +9 -0
- package/dist/types/cjs/helpers/deriveOpCacheability.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterField.d.cts +5 -0
- package/dist/types/cjs/helpers/filterField.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterFragmentDefinitions.d.cts +5 -0
- package/dist/types/cjs/helpers/filterFragmentDefinitions.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterFragmentSpreads.d.cts +5 -0
- package/dist/types/cjs/helpers/filterFragmentSpreads.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterIDsAndTypeNames.d.cts +4 -0
- package/dist/types/cjs/helpers/filterIDsAndTypeNames.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterInlineFragments.d.cts +4 -0
- package/dist/types/cjs/helpers/filterInlineFragments.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterOperationAndFragmentDefinitions.d.cts +3 -0
- package/dist/types/cjs/helpers/filterOperationAndFragmentDefinitions.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts +6 -0
- package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts.map +1 -0
- package/dist/types/cjs/helpers/filterQuery.d.cts +4 -0
- package/dist/types/cjs/helpers/filterQuery.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getDataValue.d.cts +2 -0
- package/dist/types/cjs/helpers/getDataValue.d.cts.map +1 -0
- package/dist/types/cjs/helpers/hasTypename.d.cts +3 -0
- package/dist/types/cjs/helpers/hasTypename.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isFirstResponseChunk.d.cts +4 -0
- package/dist/types/cjs/helpers/isFirstResponseChunk.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isLastResponseChunk.d.cts +4 -0
- package/dist/types/cjs/helpers/isLastResponseChunk.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isNotLastResponseChunk.d.cts +4 -0
- package/dist/types/cjs/helpers/isNotLastResponseChunk.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isNotResponseChunk.d.cts +4 -0
- package/dist/types/cjs/helpers/isNotResponseChunk.d.cts.map +1 -0
- package/dist/types/cjs/helpers/mergeObjects.d.cts +2 -0
- package/dist/types/cjs/helpers/mergeObjects.d.cts.map +1 -0
- package/dist/types/cjs/helpers/mergeResponseDataSets.d.cts +3 -0
- package/dist/types/cjs/helpers/mergeResponseDataSets.d.cts.map +1 -0
- package/dist/types/cjs/helpers/normalizePatchResponseData.d.cts +11 -0
- package/dist/types/cjs/helpers/normalizePatchResponseData.d.cts.map +1 -0
- package/dist/types/cjs/helpers/validTypeIdValue.d.cts +3 -0
- package/dist/types/cjs/helpers/validTypeIdValue.d.cts.map +1 -0
- package/dist/types/cjs/index.d.cts +3 -0
- package/dist/types/cjs/index.d.cts.map +1 -0
- package/dist/types/cjs/main.d.cts +63 -0
- package/dist/types/cjs/main.d.cts.map +1 -0
- package/dist/types/cjs/types.d.cts +131 -0
- package/dist/types/cjs/types.d.cts.map +1 -0
- package/dist/types/esm/constants.d.ts +6 -0
- package/dist/types/esm/constants.d.ts.map +1 -0
- package/dist/types/esm/debug/index.d.ts +4 -0
- package/dist/types/esm/debug/index.d.ts.map +1 -0
- package/dist/types/esm/debug/logCacheEntry.d.ts +8 -0
- package/dist/types/esm/debug/logCacheEntry.d.ts.map +1 -0
- package/dist/types/esm/debug/logCacheQuery.d.ts +8 -0
- package/dist/types/esm/debug/logCacheQuery.d.ts.map +1 -0
- package/dist/types/esm/debug/logPartialCompiled.d.ts +6 -0
- package/dist/types/esm/debug/logPartialCompiled.d.ts.map +1 -0
- package/dist/types/esm/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts +3 -0
- package/dist/types/esm/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts.map +1 -0
- package/dist/types/esm/helpers/checkFieldPathChecklist.d.ts +3 -0
- package/dist/types/esm/helpers/checkFieldPathChecklist.d.ts.map +1 -0
- package/dist/types/esm/helpers/combineData.d.ts +2 -0
- package/dist/types/esm/helpers/combineData.d.ts.map +1 -0
- package/dist/types/esm/helpers/createFragmentSpreadChecklist.d.ts +9 -0
- package/dist/types/esm/helpers/createFragmentSpreadChecklist.d.ts.map +1 -0
- package/dist/types/esm/helpers/deriveOpCacheability.d.ts +9 -0
- package/dist/types/esm/helpers/deriveOpCacheability.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterField.d.ts +5 -0
- package/dist/types/esm/helpers/filterField.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterFragmentDefinitions.d.ts +5 -0
- package/dist/types/esm/helpers/filterFragmentDefinitions.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterFragmentSpreads.d.ts +5 -0
- package/dist/types/esm/helpers/filterFragmentSpreads.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterIDsAndTypeNames.d.ts +4 -0
- package/dist/types/esm/helpers/filterIDsAndTypeNames.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterInlineFragments.d.ts +4 -0
- package/dist/types/esm/helpers/filterInlineFragments.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterOperationAndFragmentDefinitions.d.ts +3 -0
- package/dist/types/esm/helpers/filterOperationAndFragmentDefinitions.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts +6 -0
- package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +1 -0
- package/dist/types/esm/helpers/filterQuery.d.ts +4 -0
- package/dist/types/esm/helpers/filterQuery.d.ts.map +1 -0
- package/dist/types/esm/helpers/getDataValue.d.ts +2 -0
- package/dist/types/esm/helpers/getDataValue.d.ts.map +1 -0
- package/dist/types/esm/helpers/hasTypename.d.ts +3 -0
- package/dist/types/esm/helpers/hasTypename.d.ts.map +1 -0
- package/dist/types/esm/helpers/isFirstResponseChunk.d.ts +4 -0
- package/dist/types/esm/helpers/isFirstResponseChunk.d.ts.map +1 -0
- package/dist/types/esm/helpers/isLastResponseChunk.d.ts +4 -0
- package/dist/types/esm/helpers/isLastResponseChunk.d.ts.map +1 -0
- package/dist/types/esm/helpers/isNotLastResponseChunk.d.ts +4 -0
- package/dist/types/esm/helpers/isNotLastResponseChunk.d.ts.map +1 -0
- package/dist/types/esm/helpers/isNotResponseChunk.d.ts +4 -0
- package/dist/types/esm/helpers/isNotResponseChunk.d.ts.map +1 -0
- package/dist/types/esm/helpers/mergeObjects.d.ts +2 -0
- package/dist/types/esm/helpers/mergeObjects.d.ts.map +1 -0
- package/dist/types/esm/helpers/mergeResponseDataSets.d.ts +3 -0
- package/dist/types/esm/helpers/mergeResponseDataSets.d.ts.map +1 -0
- package/dist/types/esm/helpers/normalizePatchResponseData.d.ts +11 -0
- package/dist/types/esm/helpers/normalizePatchResponseData.d.ts.map +1 -0
- package/dist/types/esm/helpers/validTypeIdValue.d.ts +3 -0
- package/dist/types/esm/helpers/validTypeIdValue.d.ts.map +1 -0
- package/dist/types/esm/index.d.ts +3 -0
- package/dist/types/esm/index.d.ts.map +1 -0
- package/{lib/types/main/index.d.ts → dist/types/esm/main.d.ts} +6 -7
- package/dist/types/esm/main.d.ts.map +1 -0
- package/{lib/types/defs/index.d.ts → dist/types/esm/types.d.ts} +26 -26
- package/dist/types/esm/types.d.ts.map +1 -0
- package/dist/types/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +54 -39
- package/src/__snapshots__/index.test.ts.snap +16531 -16531
- package/src/constants.ts +6 -0
- package/src/debug/index.ts +3 -3
- package/src/debug/logCacheEntry.ts +54 -0
- package/src/debug/{log-cache-query/index.ts → logCacheQuery.ts} +23 -20
- package/src/debug/logPartialCompiled.ts +41 -0
- package/src/helpers/areOnlyPopulatedFieldsTypeIdKeys.ts +19 -12
- package/src/helpers/checkFieldPathChecklist.ts +9 -7
- package/src/helpers/combineData.ts +14 -0
- package/src/helpers/createFragmentSpreadChecklist.ts +11 -10
- package/src/helpers/deriveOpCacheability.ts +10 -6
- package/src/helpers/filterField.ts +28 -21
- package/src/helpers/filterFragmentDefinitions.ts +35 -21
- package/src/helpers/filterFragmentSpreads.ts +17 -12
- package/src/helpers/filterIDsAndTypeNames.ts +15 -11
- package/src/helpers/filterInlineFragments.ts +13 -11
- package/src/helpers/filterOperationAndFragmentDefinitions.ts +5 -5
- package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +10 -10
- package/src/helpers/filterQuery.ts +21 -12
- package/src/helpers/getDataValue.ts +14 -0
- package/src/helpers/hasTypename.ts +11 -0
- package/src/helpers/isFirstResponseChunk.ts +6 -4
- package/src/helpers/isLastResponseChunk.ts +6 -4
- package/src/helpers/isNotLastResponseChunk.ts +6 -4
- package/src/helpers/isNotResponseChunk.ts +6 -4
- package/src/helpers/mergeObjects.ts +7 -0
- package/src/helpers/mergeResponseDataSets.ts +8 -8
- package/src/helpers/normalizePatchResponseData.ts +12 -5
- package/src/helpers/validTypeIdValue.ts +18 -0
- package/src/index.test.ts +479 -450
- package/src/index.ts +2 -2
- package/src/{main/index.ts → main.ts} +287 -260
- package/src/{defs/index.ts → types.ts} +38 -43
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +17 -0
- package/lib/browser/index.js +0 -2
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/production.analysis.txt +0 -234
- package/lib/main/consts/index.js +0 -17
- package/lib/main/consts/index.js.map +0 -1
- package/lib/main/debug/index.js +0 -32
- package/lib/main/debug/index.js.map +0 -1
- package/lib/main/debug/log-cache-entry/index.js +0 -57
- package/lib/main/debug/log-cache-entry/index.js.map +0 -1
- package/lib/main/debug/log-cache-query/index.js +0 -59
- package/lib/main/debug/log-cache-query/index.js.map +0 -1
- package/lib/main/debug/log-partial-compiled/index.js +0 -50
- package/lib/main/debug/log-partial-compiled/index.js.map +0 -1
- package/lib/main/defs/index.js +0 -2
- package/lib/main/defs/index.js.map +0 -1
- package/lib/main/helpers/areOnlyPopulatedFieldsTypeIdKeys.js +0 -53
- package/lib/main/helpers/areOnlyPopulatedFieldsTypeIdKeys.js.map +0 -1
- package/lib/main/helpers/checkFieldPathChecklist.js +0 -40
- package/lib/main/helpers/checkFieldPathChecklist.js.map +0 -1
- package/lib/main/helpers/createFragmentSpreadChecklist.js +0 -26
- package/lib/main/helpers/createFragmentSpreadChecklist.js.map +0 -1
- package/lib/main/helpers/deriveOpCacheability.js +0 -46
- package/lib/main/helpers/deriveOpCacheability.js.map +0 -1
- package/lib/main/helpers/filterField.js +0 -95
- package/lib/main/helpers/filterField.js.map +0 -1
- package/lib/main/helpers/filterFragmentDefinitions.js +0 -55
- package/lib/main/helpers/filterFragmentDefinitions.js.map +0 -1
- package/lib/main/helpers/filterFragmentSpreads.js +0 -36
- package/lib/main/helpers/filterFragmentSpreads.js.map +0 -1
- package/lib/main/helpers/filterIDsAndTypeNames.js +0 -47
- package/lib/main/helpers/filterIDsAndTypeNames.js.map +0 -1
- package/lib/main/helpers/filterInlineFragments.js +0 -42
- package/lib/main/helpers/filterInlineFragments.js.map +0 -1
- package/lib/main/helpers/filterOperationAndFragmentDefinitions.js +0 -15
- package/lib/main/helpers/filterOperationAndFragmentDefinitions.js.map +0 -1
- package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js +0 -37
- package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js.map +0 -1
- package/lib/main/helpers/filterQuery.js +0 -58
- package/lib/main/helpers/filterQuery.js.map +0 -1
- package/lib/main/helpers/isFirstResponseChunk.js +0 -11
- package/lib/main/helpers/isFirstResponseChunk.js.map +0 -1
- package/lib/main/helpers/isLastResponseChunk.js +0 -11
- package/lib/main/helpers/isLastResponseChunk.js.map +0 -1
- package/lib/main/helpers/isNotLastResponseChunk.js +0 -11
- package/lib/main/helpers/isNotLastResponseChunk.js.map +0 -1
- package/lib/main/helpers/isNotResponseChunk.js +0 -11
- package/lib/main/helpers/isNotResponseChunk.js.map +0 -1
- package/lib/main/helpers/mergeResponseDataSets.js +0 -53
- package/lib/main/helpers/mergeResponseDataSets.js.map +0 -1
- package/lib/main/helpers/normalizePatchResponseData.js +0 -29
- package/lib/main/helpers/normalizePatchResponseData.js.map +0 -1
- package/lib/main/helpers/validTypeIDValue.js +0 -20
- package/lib/main/helpers/validTypeIDValue.js.map +0 -1
- package/lib/main/index.js +0 -31
- package/lib/main/index.js.map +0 -1
- package/lib/main/main/index.js +0 -1090
- package/lib/main/main/index.js.map +0 -1
- package/lib/module/consts/index.js +0 -6
- package/lib/module/consts/index.js.map +0 -1
- package/lib/module/debug/index.js +0 -4
- package/lib/module/debug/index.js.map +0 -1
- package/lib/module/debug/log-cache-entry/index.js +0 -48
- package/lib/module/debug/log-cache-entry/index.js.map +0 -1
- package/lib/module/debug/log-cache-query/index.js +0 -50
- package/lib/module/debug/log-cache-query/index.js.map +0 -1
- package/lib/module/debug/log-partial-compiled/index.js +0 -41
- package/lib/module/debug/log-partial-compiled/index.js.map +0 -1
- package/lib/module/defs/index.js +0 -2
- package/lib/module/defs/index.js.map +0 -1
- package/lib/module/helpers/areOnlyPopulatedFieldsTypeIdKeys.js +0 -41
- package/lib/module/helpers/areOnlyPopulatedFieldsTypeIdKeys.js.map +0 -1
- package/lib/module/helpers/checkFieldPathChecklist.js +0 -31
- package/lib/module/helpers/checkFieldPathChecklist.js.map +0 -1
- package/lib/module/helpers/createFragmentSpreadChecklist.js +0 -14
- package/lib/module/helpers/createFragmentSpreadChecklist.js.map +0 -1
- package/lib/module/helpers/deriveOpCacheability.js +0 -32
- package/lib/module/helpers/deriveOpCacheability.js.map +0 -1
- package/lib/module/helpers/filterField.js +0 -80
- package/lib/module/helpers/filterField.js.map +0 -1
- package/lib/module/helpers/filterFragmentDefinitions.js +0 -43
- package/lib/module/helpers/filterFragmentDefinitions.js.map +0 -1
- package/lib/module/helpers/filterFragmentSpreads.js +0 -22
- package/lib/module/helpers/filterFragmentSpreads.js.map +0 -1
- package/lib/module/helpers/filterIDsAndTypeNames.js +0 -36
- package/lib/module/helpers/filterIDsAndTypeNames.js.map +0 -1
- package/lib/module/helpers/filterInlineFragments.js +0 -32
- package/lib/module/helpers/filterInlineFragments.js.map +0 -1
- package/lib/module/helpers/filterOperationAndFragmentDefinitions.js +0 -5
- package/lib/module/helpers/filterOperationAndFragmentDefinitions.js.map +0 -1
- package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js +0 -24
- package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js.map +0 -1
- package/lib/module/helpers/filterQuery.js +0 -43
- package/lib/module/helpers/filterQuery.js.map +0 -1
- package/lib/module/helpers/isFirstResponseChunk.js +0 -2
- package/lib/module/helpers/isFirstResponseChunk.js.map +0 -1
- package/lib/module/helpers/isLastResponseChunk.js +0 -2
- package/lib/module/helpers/isLastResponseChunk.js.map +0 -1
- package/lib/module/helpers/isNotLastResponseChunk.js +0 -2
- package/lib/module/helpers/isNotLastResponseChunk.js.map +0 -1
- package/lib/module/helpers/isNotResponseChunk.js +0 -2
- package/lib/module/helpers/isNotResponseChunk.js.map +0 -1
- package/lib/module/helpers/mergeResponseDataSets.js +0 -41
- package/lib/module/helpers/mergeResponseDataSets.js.map +0 -1
- package/lib/module/helpers/normalizePatchResponseData.js +0 -17
- package/lib/module/helpers/normalizePatchResponseData.js.map +0 -1
- package/lib/module/helpers/validTypeIDValue.js +0 -8
- package/lib/module/helpers/validTypeIDValue.js.map +0 -1
- package/lib/module/index.js +0 -3
- package/lib/module/index.js.map +0 -1
- package/lib/module/main/index.js.map +0 -1
- package/lib/types/consts/index.d.ts +0 -6
- package/lib/types/consts/index.d.ts.map +0 -1
- package/lib/types/debug/index.d.ts +0 -4
- package/lib/types/debug/index.d.ts.map +0 -1
- package/lib/types/debug/log-cache-entry/index.d.ts +0 -2
- package/lib/types/debug/log-cache-entry/index.d.ts.map +0 -1
- package/lib/types/debug/log-cache-query/index.d.ts +0 -2
- package/lib/types/debug/log-cache-query/index.d.ts.map +0 -1
- package/lib/types/debug/log-partial-compiled/index.d.ts +0 -2
- package/lib/types/debug/log-partial-compiled/index.d.ts.map +0 -1
- package/lib/types/defs/index.d.ts.map +0 -1
- package/lib/types/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts +0 -4
- package/lib/types/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts.map +0 -1
- package/lib/types/helpers/checkFieldPathChecklist.d.ts +0 -4
- package/lib/types/helpers/checkFieldPathChecklist.d.ts.map +0 -1
- package/lib/types/helpers/createFragmentSpreadChecklist.d.ts +0 -12
- package/lib/types/helpers/createFragmentSpreadChecklist.d.ts.map +0 -1
- package/lib/types/helpers/deriveOpCacheability.d.ts +0 -10
- package/lib/types/helpers/deriveOpCacheability.d.ts.map +0 -1
- package/lib/types/helpers/filterField.d.ts +0 -6
- package/lib/types/helpers/filterField.d.ts.map +0 -1
- package/lib/types/helpers/filterFragmentDefinitions.d.ts +0 -6
- package/lib/types/helpers/filterFragmentDefinitions.d.ts.map +0 -1
- package/lib/types/helpers/filterFragmentSpreads.d.ts +0 -6
- package/lib/types/helpers/filterFragmentSpreads.d.ts.map +0 -1
- package/lib/types/helpers/filterIDsAndTypeNames.d.ts +0 -5
- package/lib/types/helpers/filterIDsAndTypeNames.d.ts.map +0 -1
- package/lib/types/helpers/filterInlineFragments.d.ts +0 -5
- package/lib/types/helpers/filterInlineFragments.d.ts.map +0 -1
- package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts +0 -4
- package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts.map +0 -1
- package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts +0 -7
- package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +0 -1
- package/lib/types/helpers/filterQuery.d.ts +0 -5
- package/lib/types/helpers/filterQuery.d.ts.map +0 -1
- package/lib/types/helpers/isFirstResponseChunk.d.ts +0 -5
- package/lib/types/helpers/isFirstResponseChunk.d.ts.map +0 -1
- package/lib/types/helpers/isLastResponseChunk.d.ts +0 -5
- package/lib/types/helpers/isLastResponseChunk.d.ts.map +0 -1
- package/lib/types/helpers/isNotLastResponseChunk.d.ts +0 -5
- package/lib/types/helpers/isNotLastResponseChunk.d.ts.map +0 -1
- package/lib/types/helpers/isNotResponseChunk.d.ts +0 -5
- package/lib/types/helpers/isNotResponseChunk.d.ts.map +0 -1
- package/lib/types/helpers/mergeResponseDataSets.d.ts +0 -4
- package/lib/types/helpers/mergeResponseDataSets.d.ts.map +0 -1
- package/lib/types/helpers/normalizePatchResponseData.d.ts +0 -5
- package/lib/types/helpers/normalizePatchResponseData.d.ts.map +0 -1
- package/lib/types/helpers/validTypeIDValue.d.ts +0 -3
- package/lib/types/helpers/validTypeIDValue.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.test.d.ts +0 -2
- package/lib/types/index.test.d.ts.map +0 -1
- package/lib/types/main/index.d.ts.map +0 -1
- package/src/consts/index.ts +0 -6
- package/src/debug/log-cache-entry/index.ts +0 -45
- package/src/debug/log-partial-compiled/index.ts +0 -38
- package/src/helpers/validTypeIDValue.ts +0 -11
|
@@ -1,106 +1,678 @@
|
|
|
1
|
-
import _defineProperty from
|
|
2
|
-
import _applyDecoratedDescriptor from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _applyDecoratedDescriptor from '@babel/runtime/helpers/applyDecoratedDescriptor';
|
|
3
|
+
import 'core-js/modules/es.array.push.js';
|
|
4
|
+
import { CACHE_ENTRY_ADDED, CACHE_ENTRY_QUERIED, PARTIAL_QUERY_COMPILED, TYPE_NAME_KEY, DEFAULT_TYPE_ID_KEY, QUERY_RESPONSES, DATA_ENTITIES, REQUEST_FIELD_PATHS } from '@graphql-box/core';
|
|
5
|
+
import { isPlainObject, isArray, mergeObjects, isObjectLike, resolveFragments, getName, buildFieldKeysAndPaths, deleteFragmentSpreads, getChildFields, deleteChildFields, getInlineFragments, deleteInlineFragments, hasChildFields, deleteFragmentDefinitions, getOperationDefinitions, ArgsError, GroupedError, getFragmentDefinitions, hashRequest, rehydrateCacheMetadata, iterateChildFields, dehydrateCacheMetadata } from '@graphql-box/helpers';
|
|
6
|
+
import { Cacheability } from 'cacheability';
|
|
7
|
+
import { Kind, print, OperationTypeNode } from 'graphql';
|
|
8
|
+
import { isNumber, isString, isEmpty, keys, merge, set, cloneDeep, get, isUndefined, assign, isEqual, unset } from 'lodash-es';
|
|
9
|
+
|
|
10
|
+
const METADATA = 'metadata';
|
|
11
|
+
const CACHE_CONTROL = 'cacheControl';
|
|
12
|
+
const NO_CACHE = 'noCache';
|
|
13
|
+
const HEADER_CACHE_CONTROL = 'cache-control';
|
|
14
|
+
const HEADER_NO_CACHE = 'no-cache';
|
|
15
|
+
|
|
16
|
+
const logCacheEntry = () => {
|
|
17
|
+
return (_target, _propertyName, descriptor) => {
|
|
18
|
+
const method = descriptor.value;
|
|
19
|
+
if (!method) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
descriptor.value = async function descriptorValue(...args) {
|
|
23
|
+
return new Promise(resolve => {
|
|
24
|
+
void (async () => {
|
|
25
|
+
const {
|
|
26
|
+
debugManager,
|
|
27
|
+
requestFieldCacheKey,
|
|
28
|
+
...otherContext
|
|
29
|
+
} = args[5];
|
|
30
|
+
if (!debugManager) {
|
|
31
|
+
await method.apply(this, args);
|
|
32
|
+
resolve();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const startTime = debugManager.now();
|
|
36
|
+
await method.apply(this, args);
|
|
37
|
+
const endTime = debugManager.now();
|
|
38
|
+
const duration = endTime - startTime;
|
|
39
|
+
resolve();
|
|
40
|
+
const payload = {
|
|
41
|
+
cacheType: args[0],
|
|
42
|
+
cachemapOptions: args[3],
|
|
43
|
+
context: otherContext,
|
|
44
|
+
options: args[4],
|
|
45
|
+
requestHash: args[1],
|
|
46
|
+
stats: {
|
|
47
|
+
duration,
|
|
48
|
+
endTime,
|
|
49
|
+
startTime
|
|
50
|
+
},
|
|
51
|
+
value: args[2],
|
|
52
|
+
...(requestFieldCacheKey ? {
|
|
53
|
+
decryptedCacheKey: requestFieldCacheKey
|
|
54
|
+
} : {})
|
|
55
|
+
};
|
|
56
|
+
debugManager.log(CACHE_ENTRY_ADDED, payload);
|
|
57
|
+
})();
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
12
62
|
|
|
13
|
-
|
|
63
|
+
const logCacheQuery = () => {
|
|
64
|
+
return (_target, _propertyName, descriptor) => {
|
|
65
|
+
const method = descriptor.value;
|
|
66
|
+
if (!method) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
descriptor.value = async function descriptorValue(...args) {
|
|
70
|
+
return new Promise(resolve => {
|
|
71
|
+
void (async () => {
|
|
72
|
+
const {
|
|
73
|
+
debugManager,
|
|
74
|
+
requestFieldCacheKey,
|
|
75
|
+
...otherContext
|
|
76
|
+
} = args[3];
|
|
77
|
+
if (!debugManager) {
|
|
78
|
+
resolve(await method.apply(this, args));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const startTime = debugManager.now();
|
|
82
|
+
const result = await method.apply(this, args);
|
|
83
|
+
const endTime = debugManager.now();
|
|
84
|
+
const duration = endTime - startTime;
|
|
85
|
+
resolve(result);
|
|
86
|
+
const payload = {
|
|
87
|
+
cacheType: args[0],
|
|
88
|
+
context: otherContext,
|
|
89
|
+
options: args[2],
|
|
90
|
+
requestHash: args[1],
|
|
91
|
+
result,
|
|
92
|
+
stats: {
|
|
93
|
+
duration,
|
|
94
|
+
endTime,
|
|
95
|
+
startTime
|
|
96
|
+
},
|
|
97
|
+
...(requestFieldCacheKey ? {
|
|
98
|
+
decryptedCacheKey: requestFieldCacheKey
|
|
99
|
+
} : {})
|
|
100
|
+
};
|
|
101
|
+
debugManager.log(CACHE_ENTRY_QUERIED, payload);
|
|
102
|
+
})();
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const logPartialCompiled = () => {
|
|
109
|
+
return (_target, _propertyName, descriptor) => {
|
|
110
|
+
const method = descriptor.value;
|
|
111
|
+
if (!method) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
descriptor.value = function descriptorValue(...args) {
|
|
115
|
+
const {
|
|
116
|
+
debugManager,
|
|
117
|
+
...otherContext
|
|
118
|
+
} = args[3];
|
|
119
|
+
if (!debugManager) {
|
|
120
|
+
method.apply(this, args);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const startTime = debugManager.now();
|
|
124
|
+
method.apply(this, args);
|
|
125
|
+
const endTime = debugManager.now();
|
|
126
|
+
const duration = endTime - startTime;
|
|
127
|
+
debugManager.log(PARTIAL_QUERY_COMPILED, {
|
|
128
|
+
context: otherContext,
|
|
129
|
+
options: args[2],
|
|
130
|
+
requestHash: args[0],
|
|
131
|
+
result: args[1],
|
|
132
|
+
stats: {
|
|
133
|
+
duration,
|
|
134
|
+
endTime,
|
|
135
|
+
startTime
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const checkValue = (value, typeIDKey) => {
|
|
143
|
+
if (isArray(value)) {
|
|
144
|
+
return value.reduce((acc, entry) => {
|
|
145
|
+
if (!acc) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return checkValue(entry, typeIDKey);
|
|
149
|
+
}, true);
|
|
150
|
+
}
|
|
151
|
+
if (isPlainObject(value)) {
|
|
152
|
+
return recursivelyCheckProps(value, typeIDKey);
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
};
|
|
156
|
+
const recursivelyCheckProps = (data, typeIDKey) => {
|
|
157
|
+
const keys = isPlainObject(data) ? Object.keys(data) : [...data.keys()];
|
|
158
|
+
if (keys.length === 1 && isPlainObject(data) && !!data[typeIDKey]) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return keys.reduce((acc, key) => {
|
|
162
|
+
if (!acc) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (isNumber(key) && isArray(data)) {
|
|
166
|
+
return checkValue(data[key], typeIDKey);
|
|
167
|
+
} else if (isString(key) && isPlainObject(data)) {
|
|
168
|
+
return checkValue(data[key], typeIDKey);
|
|
169
|
+
}
|
|
170
|
+
return acc;
|
|
171
|
+
}, true);
|
|
172
|
+
};
|
|
173
|
+
const areOnlyPopulatedFieldsTypeIdKeys = (data, typeIDKey) => {
|
|
174
|
+
return recursivelyCheckProps(data, typeIDKey);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const mergeDataSets = (obj, source, typeIDKey) => {
|
|
178
|
+
return mergeObjects(obj, source, (_key, value) => {
|
|
179
|
+
return isPlainObject(value) && value[typeIDKey] ? value[typeIDKey] : undefined;
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const combineDataSets = (dataSetA, dataSetB, typeIDKey) => {
|
|
184
|
+
if (!dataSetA && dataSetB) {
|
|
185
|
+
return dataSetB;
|
|
186
|
+
}
|
|
187
|
+
if (isObjectLike(dataSetA) && isObjectLike(dataSetB)) {
|
|
188
|
+
return mergeDataSets(dataSetA, dataSetB, typeIDKey);
|
|
189
|
+
}
|
|
190
|
+
return dataSetA;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const deriveOpCacheability = ({
|
|
194
|
+
_cacheMetadata,
|
|
195
|
+
fallback,
|
|
196
|
+
headers
|
|
197
|
+
}) => {
|
|
198
|
+
if (_cacheMetadata && !isEmpty(_cacheMetadata)) {
|
|
199
|
+
const [first, ...rest] = Object.values(_cacheMetadata);
|
|
200
|
+
return new Cacheability({
|
|
201
|
+
metadata: rest.reduce((acc, metadata) => {
|
|
202
|
+
if (!acc) {
|
|
203
|
+
return metadata;
|
|
204
|
+
}
|
|
205
|
+
if (metadata.ttl < acc.ttl) {
|
|
206
|
+
return metadata;
|
|
207
|
+
}
|
|
208
|
+
return acc;
|
|
209
|
+
}, first)
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (headers?.has(HEADER_CACHE_CONTROL)) {
|
|
213
|
+
return new Cacheability({
|
|
214
|
+
headers
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return new Cacheability({
|
|
218
|
+
cacheControl: fallback
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const filterOutPropsWithArgsOrDirectives = (fieldData, selectionNodes, ancestorKeysAndPaths, context) => {
|
|
223
|
+
const fieldAndTypeName = resolveFragments(selectionNodes, context.fragmentDefinitions);
|
|
224
|
+
return keys(fieldData).reduce((acc, key) => {
|
|
225
|
+
const match = fieldAndTypeName.find(({
|
|
226
|
+
fieldNode
|
|
227
|
+
}) => getName(fieldNode) === key);
|
|
228
|
+
if (match) {
|
|
229
|
+
const {
|
|
230
|
+
requestFieldPath
|
|
231
|
+
} = buildFieldKeysAndPaths(match.fieldNode, ancestorKeysAndPaths, context);
|
|
232
|
+
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
233
|
+
if (!fieldTypeInfo?.hasArguments && !fieldTypeInfo?.hasDirectives) {
|
|
234
|
+
acc[key] = fieldData[key];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return acc;
|
|
238
|
+
}, {});
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const createFragmentSpreadChecklist = ({
|
|
242
|
+
request
|
|
243
|
+
}, {
|
|
244
|
+
fragmentDefinitions
|
|
245
|
+
}) => keys(fragmentDefinitions ?? {}).reduce((acc, name) => {
|
|
246
|
+
acc[name] = {
|
|
247
|
+
deleted: 0,
|
|
248
|
+
paths: [],
|
|
249
|
+
total: (request.match(new RegExp(`\\.\\.\\.${name}`, 'g')) ?? []).length
|
|
250
|
+
};
|
|
251
|
+
return acc;
|
|
252
|
+
}, {});
|
|
253
|
+
|
|
254
|
+
const checkFieldPathChecklist = (fieldPathChecklistValues, fieldTypeName) => {
|
|
255
|
+
if (!fieldPathChecklistValues || fieldPathChecklistValues.length === 0) {
|
|
256
|
+
return {
|
|
257
|
+
hasData: false,
|
|
258
|
+
typeUnused: !!fieldTypeName
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const [fieldPathChecklistValue] = fieldPathChecklistValues;
|
|
262
|
+
if (fieldPathChecklistValue) {
|
|
263
|
+
const {
|
|
264
|
+
hasData,
|
|
265
|
+
typeName
|
|
266
|
+
} = fieldPathChecklistValue;
|
|
267
|
+
const typeUnused = typeName ? typeName !== fieldTypeName : undefined;
|
|
268
|
+
return {
|
|
269
|
+
hasData,
|
|
270
|
+
typeUnused
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
hasData: fieldPathChecklistValues.some(({
|
|
275
|
+
hasData,
|
|
276
|
+
typeName
|
|
277
|
+
}) => typeName === fieldTypeName && hasData),
|
|
278
|
+
typeUnused: !fieldPathChecklistValues.every(({
|
|
279
|
+
typeName
|
|
280
|
+
}) => typeName === fieldTypeName)
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const filterFragmentSpreads = (field, fragmentSpreadFieldCounter, fragmentSpreadChecklist, ancestorRequestFieldPath) => {
|
|
285
|
+
if (isEmpty(fragmentSpreadFieldCounter)) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
for (const key of Object.keys(fragmentSpreadFieldCounter)) {
|
|
289
|
+
const checklist = fragmentSpreadChecklist[key];
|
|
290
|
+
if (!checklist) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
checklist.paths.push(ancestorRequestFieldPath);
|
|
294
|
+
const {
|
|
295
|
+
hasData,
|
|
296
|
+
total
|
|
297
|
+
} = fragmentSpreadFieldCounter[key];
|
|
298
|
+
if (hasData === total) {
|
|
299
|
+
deleteFragmentSpreads(field, key);
|
|
300
|
+
checklist.deleted += 1;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const filterIDsAndTypeNames = (field, {
|
|
306
|
+
fragmentDefinitions,
|
|
307
|
+
typeIDKey
|
|
308
|
+
}) => {
|
|
309
|
+
const fieldsAndTypeNames = getChildFields(field, {
|
|
310
|
+
fragmentDefinitions
|
|
311
|
+
});
|
|
312
|
+
if (!fieldsAndTypeNames || fieldsAndTypeNames.length > 3) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
const fieldNames = fieldsAndTypeNames.map(({
|
|
316
|
+
fieldNode
|
|
317
|
+
}) => getName(fieldNode));
|
|
318
|
+
if (fieldNames.length === 2 && fieldNames.every(name => name === typeIDKey || name === TYPE_NAME_KEY)) {
|
|
319
|
+
deleteChildFields(field, fieldsAndTypeNames.map(({
|
|
320
|
+
fieldNode
|
|
321
|
+
}) => fieldNode));
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
if (fieldNames.length === 1 && fieldNames[0] === typeIDKey || fieldNames[0] === TYPE_NAME_KEY) {
|
|
325
|
+
const [fieldAndTypeName] = fieldsAndTypeNames;
|
|
326
|
+
if (fieldAndTypeName) {
|
|
327
|
+
const {
|
|
328
|
+
fieldNode
|
|
329
|
+
} = fieldAndTypeName;
|
|
330
|
+
deleteChildFields(field, fieldNode);
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return false;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const filterInlineFragments = (field, {
|
|
338
|
+
fragmentDefinitions,
|
|
339
|
+
typeIDKey
|
|
340
|
+
}) => {
|
|
341
|
+
const inlineFragments = getInlineFragments(field);
|
|
342
|
+
let filtered = false;
|
|
343
|
+
for (const fragment of inlineFragments) {
|
|
344
|
+
const fieldsAndTypeNames = getChildFields(fragment, {
|
|
345
|
+
fragmentDefinitions
|
|
346
|
+
});
|
|
347
|
+
if (!fieldsAndTypeNames || fieldsAndTypeNames.length === 0) {
|
|
348
|
+
deleteInlineFragments(field, fragment);
|
|
349
|
+
filtered = true;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const [fieldAndTypeName] = fieldsAndTypeNames;
|
|
353
|
+
if (fieldAndTypeName) {
|
|
354
|
+
const {
|
|
355
|
+
fieldNode
|
|
356
|
+
} = fieldAndTypeName;
|
|
357
|
+
if (getName(fieldNode) === typeIDKey) {
|
|
358
|
+
deleteInlineFragments(field, fragment);
|
|
359
|
+
filtered = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return filtered;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const filterField = (field, fieldPathChecklist, fragmentSpreadChecklist, ancestorRequestFieldPath, context) => {
|
|
367
|
+
const {
|
|
368
|
+
fragmentDefinitions,
|
|
369
|
+
typeIDKey
|
|
370
|
+
} = context;
|
|
371
|
+
const fieldsAndTypeNames = getChildFields(field, {
|
|
372
|
+
fragmentDefinitions
|
|
373
|
+
});
|
|
374
|
+
if (!fieldsAndTypeNames) {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
const fragmentSpreadFieldCounter = {};
|
|
378
|
+
for (let index = fieldsAndTypeNames.length - 1; index >= 0; index -= 1) {
|
|
379
|
+
const fieldAndTypeName = fieldsAndTypeNames[index];
|
|
380
|
+
if (!fieldAndTypeName) {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
const {
|
|
384
|
+
fieldNode: childField,
|
|
385
|
+
fragmentKind,
|
|
386
|
+
fragmentName,
|
|
387
|
+
typeName: childTypeName
|
|
388
|
+
} = fieldAndTypeName;
|
|
389
|
+
if (fragmentKind === Kind.FRAGMENT_SPREAD && fragmentName && !fragmentSpreadFieldCounter[fragmentName]) {
|
|
390
|
+
fragmentSpreadFieldCounter[fragmentName] = {
|
|
391
|
+
hasData: 0,
|
|
392
|
+
total: fragmentDefinitions?.[fragmentName] ? getChildFields(fragmentDefinitions[fragmentName], {
|
|
393
|
+
fragmentDefinitions
|
|
394
|
+
})?.length ?? 0 : 0
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const childFieldName = getName(childField);
|
|
398
|
+
if (childFieldName === typeIDKey || childFieldName === TYPE_NAME_KEY) {
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const {
|
|
402
|
+
requestFieldPath
|
|
403
|
+
} = buildFieldKeysAndPaths(childField, {
|
|
404
|
+
requestFieldPath: ancestorRequestFieldPath
|
|
405
|
+
}, context);
|
|
406
|
+
const {
|
|
407
|
+
hasData,
|
|
408
|
+
typeUnused
|
|
409
|
+
} = checkFieldPathChecklist(fieldPathChecklist.get(requestFieldPath), childTypeName);
|
|
410
|
+
if (hasData || typeUnused) {
|
|
411
|
+
if (fragmentKind === Kind.FRAGMENT_SPREAD && fragmentName) {
|
|
412
|
+
const counter = fragmentSpreadFieldCounter[fragmentName];
|
|
413
|
+
if (counter) {
|
|
414
|
+
counter.hasData += 1;
|
|
415
|
+
}
|
|
416
|
+
} else if (!hasChildFields(childField, {
|
|
417
|
+
fragmentDefinitions
|
|
418
|
+
})) {
|
|
419
|
+
deleteChildFields(field, childField);
|
|
420
|
+
} else if (filterField(childField, fieldPathChecklist, fragmentSpreadChecklist, requestFieldPath, context)) {
|
|
421
|
+
deleteChildFields(field, childField);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
filterFragmentSpreads(field, fragmentSpreadFieldCounter, fragmentSpreadChecklist, ancestorRequestFieldPath);
|
|
426
|
+
filterInlineFragments(field, context);
|
|
427
|
+
filterIDsAndTypeNames(field, context);
|
|
428
|
+
return !hasChildFields(field, {
|
|
429
|
+
fragmentDefinitions
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
const filterFragmentDefinitions = (ast, fieldPathChecklist, fragmentSpreadChecklist, context) => {
|
|
434
|
+
const definitionsToFilter = keys(fragmentSpreadChecklist).reduce((namesAndPaths, key) => {
|
|
435
|
+
const checklist = fragmentSpreadChecklist[key];
|
|
436
|
+
if (!checklist) {
|
|
437
|
+
return namesAndPaths;
|
|
438
|
+
}
|
|
439
|
+
const {
|
|
440
|
+
deleted,
|
|
441
|
+
paths,
|
|
442
|
+
total
|
|
443
|
+
} = checklist;
|
|
444
|
+
return deleted === 0 && total === 1 ? [...namesAndPaths, {
|
|
445
|
+
name: key,
|
|
446
|
+
path: paths[0]
|
|
447
|
+
}] : namesAndPaths;
|
|
448
|
+
}, []);
|
|
449
|
+
const {
|
|
450
|
+
fragmentDefinitions = {}
|
|
451
|
+
} = context;
|
|
452
|
+
for (const {
|
|
453
|
+
name,
|
|
454
|
+
path
|
|
455
|
+
} of definitionsToFilter) {
|
|
456
|
+
const fragmentDefinition = fragmentDefinitions[name];
|
|
457
|
+
if (!fragmentDefinition) {
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
filterField(fragmentDefinition, fieldPathChecklist, fragmentSpreadChecklist, path, context);
|
|
461
|
+
}
|
|
462
|
+
const definitionsToDelete = keys(fragmentSpreadChecklist).reduce((names, key) => {
|
|
463
|
+
const checklist = fragmentSpreadChecklist[key];
|
|
464
|
+
if (!checklist) {
|
|
465
|
+
return names;
|
|
466
|
+
}
|
|
467
|
+
const {
|
|
468
|
+
deleted,
|
|
469
|
+
total
|
|
470
|
+
} = checklist;
|
|
471
|
+
return deleted > 0 && deleted === total ? [...names, key] : names;
|
|
472
|
+
}, []);
|
|
473
|
+
if (definitionsToDelete.length === 0) {
|
|
474
|
+
return ast;
|
|
475
|
+
}
|
|
476
|
+
return deleteFragmentDefinitions(ast, {
|
|
477
|
+
include: definitionsToDelete
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
const filterQuery = (requestData, {
|
|
482
|
+
fieldPathChecklist
|
|
483
|
+
}, context) => {
|
|
484
|
+
const {
|
|
485
|
+
ast
|
|
486
|
+
} = requestData;
|
|
487
|
+
const queryNode = getOperationDefinitions(ast, context.operation)[0];
|
|
488
|
+
if (!queryNode) {
|
|
489
|
+
return ast;
|
|
490
|
+
}
|
|
491
|
+
const {
|
|
492
|
+
fragmentDefinitions,
|
|
493
|
+
operation
|
|
494
|
+
} = context;
|
|
495
|
+
const fieldsAndTypeNames = getChildFields(queryNode, {
|
|
496
|
+
fragmentDefinitions
|
|
497
|
+
});
|
|
498
|
+
if (!fieldsAndTypeNames) {
|
|
499
|
+
return ast;
|
|
500
|
+
}
|
|
501
|
+
const fragmentSpreadChecklist = createFragmentSpreadChecklist(requestData, context);
|
|
502
|
+
for (let index = fieldsAndTypeNames.length - 1; index >= 0; index -= 1) {
|
|
503
|
+
const {
|
|
504
|
+
fieldNode
|
|
505
|
+
} = fieldsAndTypeNames[index];
|
|
506
|
+
const {
|
|
507
|
+
requestFieldPath
|
|
508
|
+
} = buildFieldKeysAndPaths(fieldNode, {
|
|
509
|
+
requestFieldPath: operation
|
|
510
|
+
}, context);
|
|
511
|
+
if (filterField(fieldNode, fieldPathChecklist, fragmentSpreadChecklist, requestFieldPath, context)) {
|
|
512
|
+
deleteChildFields(queryNode, fieldNode);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
context.queryFiltered = true;
|
|
516
|
+
return filterFragmentDefinitions(ast, fieldPathChecklist, fragmentSpreadChecklist, context);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const getDataValue = (value, key) => {
|
|
520
|
+
if (isArray(value) && isNumber(key)) {
|
|
521
|
+
return value[key];
|
|
522
|
+
}
|
|
523
|
+
if (isPlainObject(value) && isString(key)) {
|
|
524
|
+
return value[key];
|
|
525
|
+
}
|
|
526
|
+
return;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
const hasTypename = value => {
|
|
530
|
+
if (!isObjectLike(value)) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
return TYPE_NAME_KEY in value && isString(value[TYPE_NAME_KEY]);
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
const isLastResponseChunk = (rawResponseData, context) => context.hasDeferOrStream && !rawResponseData.hasNext && rawResponseData.paths;
|
|
537
|
+
|
|
538
|
+
const isNotLastResponseChunk = (rawResponseData, context) => context.hasDeferOrStream && rawResponseData.hasNext;
|
|
539
|
+
|
|
540
|
+
const isNotResponseChunk = (rawResponseData, context) => !context.hasDeferOrStream && !rawResponseData.hasNext && !rawResponseData.paths;
|
|
541
|
+
|
|
542
|
+
const mergeResponseDataSets = responseDataSets => {
|
|
543
|
+
return responseDataSets.reduce((acc, dataSet, index) => {
|
|
544
|
+
const {
|
|
545
|
+
_cacheMetadata,
|
|
546
|
+
data,
|
|
547
|
+
hasNext,
|
|
548
|
+
headers,
|
|
549
|
+
paths
|
|
550
|
+
} = dataSet;
|
|
551
|
+
if (_cacheMetadata) {
|
|
552
|
+
acc._cacheMetadata = acc._cacheMetadata ? {
|
|
553
|
+
...acc._cacheMetadata,
|
|
554
|
+
..._cacheMetadata
|
|
555
|
+
} : _cacheMetadata;
|
|
556
|
+
}
|
|
557
|
+
acc.data = merge(acc.data, data);
|
|
558
|
+
if (index === 0) {
|
|
559
|
+
acc.headers = headers;
|
|
560
|
+
}
|
|
561
|
+
if (index === responseDataSets.length - 1) {
|
|
562
|
+
acc.hasNext = hasNext;
|
|
563
|
+
}
|
|
564
|
+
if (paths) {
|
|
565
|
+
if (!acc.paths) {
|
|
566
|
+
acc.paths = [];
|
|
567
|
+
}
|
|
568
|
+
acc.paths.push(...paths);
|
|
569
|
+
}
|
|
570
|
+
return acc;
|
|
571
|
+
}, {
|
|
572
|
+
data: {}
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const normalizePatchResponseData = (rawResponseData, context) => {
|
|
577
|
+
if (!context.normalizePatchResponseData) {
|
|
578
|
+
return rawResponseData;
|
|
579
|
+
}
|
|
580
|
+
const {
|
|
581
|
+
data,
|
|
582
|
+
paths,
|
|
583
|
+
...rest
|
|
584
|
+
} = rawResponseData;
|
|
585
|
+
if (!paths?.length || !isString(paths[0])) {
|
|
586
|
+
return rawResponseData;
|
|
587
|
+
}
|
|
588
|
+
return {
|
|
589
|
+
...rest,
|
|
590
|
+
data: set({}, paths[0], data),
|
|
591
|
+
paths
|
|
592
|
+
};
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
const getValidTypeIdValue = (requestFieldPathData, {
|
|
596
|
+
typeIDValue
|
|
597
|
+
}, typeIDKey) => {
|
|
598
|
+
if (typeIDValue) {
|
|
599
|
+
return typeIDValue;
|
|
600
|
+
}
|
|
601
|
+
if (isPlainObject(requestFieldPathData)) {
|
|
602
|
+
return requestFieldPathData[typeIDKey];
|
|
603
|
+
}
|
|
604
|
+
return;
|
|
605
|
+
};
|
|
14
606
|
|
|
15
|
-
|
|
16
|
-
import { DATA_ENTITIES, DEFAULT_TYPE_ID_KEY, QUERY, QUERY_RESPONSES, REQUEST_FIELD_PATHS, TYPE_NAME_KEY } from "@graphql-box/core";
|
|
17
|
-
import { FRAGMENT_SPREAD, buildFieldKeysAndPaths, dehydrateCacheMetadata, getChildFields, getFragmentDefinitions, getOperationDefinitions, hasChildFields, hashRequest, iterateChildFields, mergeObjects, rehydrateCacheMetadata } from "@graphql-box/helpers";
|
|
18
|
-
import Cacheability from "cacheability";
|
|
19
|
-
import { print } from "graphql";
|
|
20
|
-
import { CACHE_CONTROL, HEADER_NO_CACHE, METADATA, NO_CACHE } from "../consts";
|
|
21
|
-
import { logCacheEntry, logCacheQuery, logPartialCompiled } from "../debug";
|
|
22
|
-
import areOnlyPopulatedFieldsTypeIdKeys from "../helpers/areOnlyPopulatedFieldsTypeIdKeys";
|
|
23
|
-
import deriveOpCacheability from "../helpers/deriveOpCacheability";
|
|
24
|
-
import filterOutPropsWithArgsOrDirectives from "../helpers/filterOutPropsWithArgsOrDirectives";
|
|
25
|
-
import filterQuery from "../helpers/filterQuery";
|
|
26
|
-
import isLastResponseChunk from "../helpers/isLastResponseChunk";
|
|
27
|
-
import isNotLastResponseChunk from "../helpers/isNotLastResponseChunk";
|
|
28
|
-
import isNotResponseChunk from "../helpers/isNotResponseChunk";
|
|
29
|
-
import mergeResponseDataSets from "../helpers/mergeResponseDataSets";
|
|
30
|
-
import normalizePatchResponseData from "../helpers/normalizePatchResponseData";
|
|
31
|
-
import { getValidTypeIDValue } from "../helpers/validTypeIDValue";
|
|
607
|
+
var _dec, _dec2, _dec3, _class;
|
|
32
608
|
let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = logPartialCompiled(), (_class = class CacheManager {
|
|
33
609
|
static _countFieldPathChecklist(fieldPathChecklist) {
|
|
34
610
|
const fieldCount = {
|
|
35
611
|
missing: 0,
|
|
36
612
|
total: 0
|
|
37
613
|
};
|
|
38
|
-
|
|
614
|
+
for (const [, checklistValues] of fieldPathChecklist) {
|
|
39
615
|
fieldCount.total += checklistValues.length;
|
|
40
616
|
const missing = checklistValues.filter(({
|
|
41
617
|
hasData
|
|
42
618
|
}) => !hasData);
|
|
43
619
|
fieldCount.missing += missing.length;
|
|
44
|
-
}
|
|
620
|
+
}
|
|
45
621
|
return fieldCount;
|
|
46
622
|
}
|
|
47
|
-
|
|
48
623
|
static _getFieldDataFromAncestor(ancestorFieldData, propNameOrIndex) {
|
|
49
|
-
|
|
624
|
+
const dataValue = getDataValue(ancestorFieldData, propNameOrIndex);
|
|
625
|
+
return isObjectLike(dataValue) ? cloneDeep(dataValue) : dataValue;
|
|
50
626
|
}
|
|
51
|
-
|
|
52
627
|
static _getOperationCacheControl(cacheMetadata, operation) {
|
|
53
628
|
const defaultCacheControl = HEADER_NO_CACHE;
|
|
54
|
-
|
|
55
629
|
if (!cacheMetadata) {
|
|
56
630
|
return defaultCacheControl;
|
|
57
631
|
}
|
|
58
|
-
|
|
59
632
|
const cacheability = cacheMetadata.get(operation);
|
|
60
633
|
return cacheability ? cacheability.printCacheControl() : defaultCacheControl;
|
|
61
634
|
}
|
|
62
|
-
|
|
63
635
|
static _isNodeEntity(fieldTypeInfo) {
|
|
64
636
|
if (!fieldTypeInfo) {
|
|
65
637
|
return false;
|
|
66
638
|
}
|
|
67
|
-
|
|
68
639
|
const {
|
|
69
640
|
isEntity,
|
|
70
641
|
possibleTypes
|
|
71
642
|
} = fieldTypeInfo;
|
|
72
643
|
return isEntity || possibleTypes.some(type => !!type.isEntity);
|
|
73
644
|
}
|
|
74
|
-
|
|
75
645
|
static _isNodeRequestFieldPath(fieldTypeInfo) {
|
|
76
646
|
return !!fieldTypeInfo && (this._isNodeEntity(fieldTypeInfo) || fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives);
|
|
77
647
|
}
|
|
78
|
-
|
|
79
648
|
static _isValid(cacheability) {
|
|
80
|
-
const noCache =
|
|
81
|
-
|
|
649
|
+
const noCache = get(cacheability, [METADATA, CACHE_CONTROL, NO_CACHE], false);
|
|
82
650
|
return !noCache && cacheability.checkTTL();
|
|
83
651
|
}
|
|
84
|
-
|
|
85
652
|
static _mergeResponseCacheMetadata(cacheMetadata, partialQueryResponse) {
|
|
86
653
|
if (!partialQueryResponse) {
|
|
87
654
|
return cacheMetadata;
|
|
88
655
|
}
|
|
89
|
-
|
|
90
656
|
return new Map([...partialQueryResponse.cacheMetadata, ...cacheMetadata]);
|
|
91
657
|
}
|
|
92
|
-
|
|
93
|
-
static _setCachedData(requestData, {
|
|
658
|
+
static _setCachedData(responseData, {
|
|
94
659
|
data
|
|
95
660
|
}, propNameOrIndex) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
661
|
+
const setData = value => {
|
|
662
|
+
if (isArray(responseData) && isNumber(propNameOrIndex)) {
|
|
663
|
+
responseData[propNameOrIndex] = value;
|
|
664
|
+
} else if (isPlainObject(responseData)) {
|
|
665
|
+
responseData[propNameOrIndex] = value;
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
if (!isObjectLike(data) && !isUndefined(data)) {
|
|
669
|
+
setData(data);
|
|
670
|
+
} else if (isArray(data)) {
|
|
671
|
+
setData([]);
|
|
672
|
+
} else if (isPlainObject(data)) {
|
|
673
|
+
setData({});
|
|
101
674
|
}
|
|
102
675
|
}
|
|
103
|
-
|
|
104
676
|
static _setCachedResponseData(cachedFieldData, {
|
|
105
677
|
cacheMetadata,
|
|
106
678
|
data,
|
|
@@ -112,121 +684,87 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
112
684
|
operation
|
|
113
685
|
}) {
|
|
114
686
|
CacheManager._setCacheMetadata(cacheMetadata, cachedFieldData.cacheability, requestFieldPath, operation);
|
|
115
|
-
|
|
116
687
|
CacheManager._setFieldPathChecklist(fieldPathChecklist, cachedFieldData, requestFieldPath, typeNamesAndKind);
|
|
117
|
-
|
|
118
688
|
CacheManager._setCachedData(data, cachedFieldData, propNameOrIndex);
|
|
119
689
|
}
|
|
120
|
-
|
|
121
690
|
static _setCacheMetadata(cacheMetadata, cacheability, requestFieldPath, operation) {
|
|
122
691
|
if (!cacheability) {
|
|
123
692
|
return;
|
|
124
693
|
}
|
|
125
|
-
|
|
126
694
|
cacheMetadata.set(requestFieldPath, cacheability);
|
|
127
695
|
const operationCacheability = cacheMetadata.get(operation);
|
|
128
|
-
|
|
129
696
|
if (!operationCacheability || operationCacheability.metadata.ttl > cacheability.metadata.ttl) {
|
|
130
697
|
cacheMetadata.set(operation, cacheability);
|
|
131
698
|
}
|
|
132
699
|
}
|
|
133
|
-
|
|
134
700
|
static _setFieldPathChecklist(fieldPathChecklist, {
|
|
135
701
|
data
|
|
136
702
|
}, requestFieldPath, {
|
|
137
|
-
dataTypeName,
|
|
138
|
-
fieldTypeName,
|
|
703
|
+
dataTypename: dataTypeName,
|
|
704
|
+
fieldTypename: fieldTypeName,
|
|
139
705
|
fragmentKind,
|
|
140
706
|
fragmentName
|
|
141
707
|
}) {
|
|
142
|
-
if (
|
|
708
|
+
if (isUndefined(fieldTypeName) || fragmentKind === Kind.FRAGMENT_SPREAD) {
|
|
143
709
|
if (fieldPathChecklist.has(requestFieldPath)) {
|
|
144
710
|
return;
|
|
145
711
|
}
|
|
146
|
-
|
|
147
712
|
fieldPathChecklist.set(requestFieldPath, [{
|
|
148
713
|
fragmentKind,
|
|
149
714
|
fragmentName,
|
|
150
|
-
hasData: !
|
|
715
|
+
hasData: !isUndefined(data)
|
|
151
716
|
}]);
|
|
152
717
|
return;
|
|
153
718
|
}
|
|
154
|
-
|
|
155
719
|
if (dataTypeName !== fieldTypeName) {
|
|
156
720
|
return;
|
|
157
721
|
}
|
|
158
|
-
|
|
159
722
|
const entry = fieldPathChecklist.get(requestFieldPath);
|
|
160
|
-
const checklistValues = entry
|
|
161
|
-
|
|
723
|
+
const checklistValues = entry ?? [];
|
|
162
724
|
if (checklistValues.some(({
|
|
163
725
|
typeName
|
|
164
726
|
}) => typeName === dataTypeName)) {
|
|
165
727
|
return;
|
|
166
728
|
}
|
|
167
|
-
|
|
168
729
|
fieldPathChecklist.set(requestFieldPath, [...checklistValues, {
|
|
169
730
|
fragmentKind,
|
|
170
731
|
fragmentName,
|
|
171
|
-
hasData: !
|
|
732
|
+
hasData: !isUndefined(data),
|
|
172
733
|
typeName: dataTypeName
|
|
173
734
|
}]);
|
|
174
735
|
}
|
|
175
|
-
|
|
176
736
|
constructor(options) {
|
|
177
|
-
var _options$typeIDKey;
|
|
178
|
-
|
|
179
737
|
_defineProperty(this, "_cache", void 0);
|
|
180
|
-
|
|
181
738
|
_defineProperty(this, "_cascadeCacheControl", void 0);
|
|
182
|
-
|
|
183
739
|
_defineProperty(this, "_fallbackOperationCacheability", void 0);
|
|
184
|
-
|
|
185
740
|
_defineProperty(this, "_partialQueryResponses", new Map());
|
|
186
|
-
|
|
187
741
|
_defineProperty(this, "_responseChunksAwaitingCaching", new Map());
|
|
188
|
-
|
|
189
742
|
_defineProperty(this, "_typeCacheDirectives", void 0);
|
|
190
|
-
|
|
191
743
|
_defineProperty(this, "_typeIDKey", void 0);
|
|
192
|
-
|
|
193
744
|
const errors = [];
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
errors.push(new TypeError("@graphql-box/cache-manager expected options.cache."));
|
|
745
|
+
if (!('cache' in options)) {
|
|
746
|
+
errors.push(new ArgsError('@graphql-box/cache-manager expected cache to be in options.'));
|
|
197
747
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
errors.push(new TypeError(message));
|
|
748
|
+
if (!!options.typeCacheDirectives && !isPlainObject(options.typeCacheDirectives)) {
|
|
749
|
+
const message = '@graphql-box/cache-manager expected options.typeCacheDirectives to be a plain object.';
|
|
750
|
+
errors.push(new ArgsError(message));
|
|
202
751
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
throw errors;
|
|
752
|
+
if (errors.length > 0) {
|
|
753
|
+
throw new GroupedError('@graphql-box/cache-manager argument validation errors.', errors);
|
|
206
754
|
}
|
|
207
|
-
|
|
208
755
|
this._cache = options.cache;
|
|
209
|
-
this._cascadeCacheControl = options.cascadeCacheControl
|
|
210
|
-
this._fallbackOperationCacheability = options.fallbackOperationCacheability
|
|
211
|
-
this._typeCacheDirectives = options.typeCacheDirectives
|
|
212
|
-
this._typeIDKey =
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
get cache() {
|
|
216
|
-
return this._cache;
|
|
756
|
+
this._cascadeCacheControl = options.cascadeCacheControl ?? false;
|
|
757
|
+
this._fallbackOperationCacheability = options.fallbackOperationCacheability ?? NO_CACHE;
|
|
758
|
+
this._typeCacheDirectives = options.typeCacheDirectives ?? {};
|
|
759
|
+
this._typeIDKey = options.typeIDKey ?? DEFAULT_TYPE_ID_KEY;
|
|
217
760
|
}
|
|
218
|
-
|
|
219
761
|
async analyzeQuery(requestData, options, context) {
|
|
220
762
|
const {
|
|
221
763
|
ast,
|
|
222
764
|
hash
|
|
223
765
|
} = requestData;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return Promise.reject(new TypeError("@graphql-box/cache-manager expected an AST."));
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const cacheManagerContext = { ...context,
|
|
766
|
+
const cacheManagerContext = {
|
|
767
|
+
...context,
|
|
230
768
|
fragmentDefinitions: getFragmentDefinitions(ast),
|
|
231
769
|
typeIDKey: this._typeIDKey
|
|
232
770
|
};
|
|
@@ -236,23 +774,19 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
236
774
|
data,
|
|
237
775
|
fieldCount
|
|
238
776
|
} = cachedResponseData;
|
|
239
|
-
|
|
240
777
|
if (fieldCount.missing === fieldCount.total || areOnlyPopulatedFieldsTypeIdKeys(data, this._typeIDKey)) {
|
|
241
778
|
return {
|
|
242
779
|
updated: requestData
|
|
243
780
|
};
|
|
244
781
|
}
|
|
245
|
-
|
|
246
782
|
if (!fieldCount.missing) {
|
|
247
783
|
const dataCaching = this._setQueryResponseCacheEntry(hash, {
|
|
248
784
|
cacheMetadata,
|
|
249
785
|
data
|
|
250
786
|
}, options, cacheManagerContext);
|
|
251
|
-
|
|
252
787
|
if (options.awaitDataCaching) {
|
|
253
788
|
await dataCaching;
|
|
254
789
|
}
|
|
255
|
-
|
|
256
790
|
return {
|
|
257
791
|
response: {
|
|
258
792
|
cacheMetadata,
|
|
@@ -260,7 +794,6 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
260
794
|
}
|
|
261
795
|
};
|
|
262
796
|
}
|
|
263
|
-
|
|
264
797
|
const filteredAST = filterQuery(requestData, cachedResponseData, cacheManagerContext);
|
|
265
798
|
const filteredRequest = print(filteredAST);
|
|
266
799
|
const {
|
|
@@ -268,16 +801,14 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
268
801
|
typeIDKey,
|
|
269
802
|
...rest
|
|
270
803
|
} = cacheManagerContext;
|
|
271
|
-
|
|
272
|
-
|
|
804
|
+
assign(context, {
|
|
805
|
+
...rest,
|
|
273
806
|
filteredRequest
|
|
274
807
|
});
|
|
275
|
-
|
|
276
808
|
this._setPartialQueryResponse(hash, {
|
|
277
809
|
cacheMetadata,
|
|
278
810
|
data
|
|
279
811
|
}, options, context);
|
|
280
|
-
|
|
281
812
|
return {
|
|
282
813
|
updated: {
|
|
283
814
|
ast: filteredAST,
|
|
@@ -286,34 +817,33 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
286
817
|
}
|
|
287
818
|
};
|
|
288
819
|
}
|
|
289
|
-
|
|
820
|
+
get cache() {
|
|
821
|
+
return this._cache;
|
|
822
|
+
}
|
|
290
823
|
async cacheQuery(requestData, updatedRequestData, rawResponseData, options, context) {
|
|
291
|
-
const cacheManagerContext = {
|
|
292
|
-
|
|
824
|
+
const cacheManagerContext = {
|
|
825
|
+
...context,
|
|
826
|
+
fragmentDefinitions: getFragmentDefinitions((updatedRequestData ?? requestData).ast),
|
|
293
827
|
typeIDKey: this._typeIDKey
|
|
294
828
|
};
|
|
295
829
|
return this._cacheResponse(requestData, updatedRequestData, rawResponseData, options, cacheManagerContext);
|
|
296
830
|
}
|
|
297
|
-
|
|
298
831
|
async cacheResponse(requestData, rawResponseData, options, context) {
|
|
299
|
-
const cacheManagerContext = {
|
|
832
|
+
const cacheManagerContext = {
|
|
833
|
+
...context,
|
|
300
834
|
fragmentDefinitions: getFragmentDefinitions(requestData.ast),
|
|
301
835
|
typeIDKey: this._typeIDKey
|
|
302
836
|
};
|
|
303
837
|
return this._cacheResponse(requestData, undefined, rawResponseData, options, cacheManagerContext);
|
|
304
838
|
}
|
|
305
|
-
|
|
306
839
|
async checkCacheEntry(cacheType, hash, options, context) {
|
|
307
840
|
return this._checkCacheEntry(cacheType, hash, options, context);
|
|
308
841
|
}
|
|
309
|
-
|
|
310
842
|
async checkQueryResponseCacheEntry(hash, options, context) {
|
|
311
843
|
const result = await this._checkCacheEntry(QUERY_RESPONSES, hash, options, context);
|
|
312
|
-
|
|
313
844
|
if (!result) {
|
|
314
845
|
return false;
|
|
315
846
|
}
|
|
316
|
-
|
|
317
847
|
const {
|
|
318
848
|
cacheMetadata,
|
|
319
849
|
data
|
|
@@ -323,25 +853,17 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
323
853
|
data
|
|
324
854
|
};
|
|
325
855
|
}
|
|
326
|
-
|
|
327
856
|
deletePartialQueryResponse(hash) {
|
|
328
857
|
this._partialQueryResponses.delete(hash);
|
|
329
858
|
}
|
|
330
|
-
|
|
331
859
|
async setQueryResponseCacheEntry(requestData, responseData, options, context) {
|
|
332
860
|
return this._setQueryResponseCacheEntry(requestData.hash, responseData, options, context);
|
|
333
861
|
}
|
|
334
|
-
|
|
335
862
|
async _analyzeFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
336
|
-
|
|
863
|
+
await (hasChildFields(fieldNode, {
|
|
337
864
|
fragmentDefinitions: context.fragmentDefinitions
|
|
338
|
-
}))
|
|
339
|
-
await this._analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
|
|
340
|
-
} else {
|
|
341
|
-
await this._analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
|
|
342
|
-
}
|
|
865
|
+
}) ? this._analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) : this._analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context));
|
|
343
866
|
}
|
|
344
|
-
|
|
345
867
|
async _analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
346
868
|
const keysAndPaths = buildFieldKeysAndPaths(fieldNode, cachedAncestorFieldData, context);
|
|
347
869
|
const {
|
|
@@ -358,36 +880,32 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
358
880
|
requestFieldPathData,
|
|
359
881
|
typeName
|
|
360
882
|
} = cachedAncestorFieldData;
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
883
|
+
const dataTypename = hasTypename(entityData) ? entityData.__typename : hasTypename(requestFieldPathData) ? requestFieldPathData.__typename : undefined;
|
|
884
|
+
const typenamesAndKind = {
|
|
885
|
+
dataTypename,
|
|
886
|
+
fieldTypename: typeName,
|
|
364
887
|
fragmentKind,
|
|
365
888
|
fragmentName
|
|
366
889
|
};
|
|
367
|
-
|
|
368
890
|
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
369
891
|
const {
|
|
370
892
|
cacheability,
|
|
371
893
|
entry
|
|
372
894
|
} = await this._retrieveCachedRequestFieldPathData(hashedRequestFieldCacheKey, requestFieldCacheKey, options, context);
|
|
373
|
-
|
|
374
895
|
CacheManager._setCachedResponseData({
|
|
375
896
|
cacheability,
|
|
376
897
|
data: entry
|
|
377
|
-
}, cachedResponseData, keysAndPaths,
|
|
898
|
+
}, cachedResponseData, keysAndPaths, typenamesAndKind, options, context);
|
|
378
899
|
} else {
|
|
379
|
-
const cachedFieldData = CacheManager._getFieldDataFromAncestor(entityData, propNameOrIndex)
|
|
380
|
-
|
|
900
|
+
const cachedFieldData = CacheManager._getFieldDataFromAncestor(entityData, propNameOrIndex) ?? CacheManager._getFieldDataFromAncestor(requestFieldPathData, propNameOrIndex);
|
|
381
901
|
CacheManager._setFieldPathChecklist(cachedResponseData.fieldPathChecklist, {
|
|
382
902
|
data: cachedFieldData
|
|
383
|
-
}, requestFieldPath,
|
|
384
|
-
|
|
903
|
+
}, requestFieldPath, typenamesAndKind);
|
|
385
904
|
CacheManager._setCachedData(cachedResponseData.data, {
|
|
386
905
|
data: cachedFieldData
|
|
387
906
|
}, propNameOrIndex);
|
|
388
907
|
}
|
|
389
908
|
}
|
|
390
|
-
|
|
391
909
|
async _analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
392
910
|
const keysAndPaths = buildFieldKeysAndPaths(fieldNode, cachedAncestorFieldData, context);
|
|
393
911
|
const {
|
|
@@ -407,24 +925,20 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
407
925
|
fragmentName,
|
|
408
926
|
typeName
|
|
409
927
|
} = cachedAncestorFieldData;
|
|
410
|
-
|
|
411
928
|
CacheManager._setCachedResponseData({
|
|
412
929
|
cacheability,
|
|
413
930
|
data
|
|
414
931
|
}, cachedResponseData, keysAndPaths, {
|
|
415
|
-
|
|
416
|
-
|
|
932
|
+
dataTypename: get(data, TYPE_NAME_KEY),
|
|
933
|
+
fieldTypename: typeName,
|
|
417
934
|
fragmentKind,
|
|
418
935
|
fragmentName
|
|
419
936
|
}, options, context);
|
|
420
|
-
|
|
421
|
-
if (!_isObjectLike(data)) {
|
|
937
|
+
if (!isObjectLike(data)) {
|
|
422
938
|
return;
|
|
423
939
|
}
|
|
424
|
-
|
|
425
|
-
const objectLikeData = data;
|
|
426
940
|
const promises = [];
|
|
427
|
-
iterateChildFields(fieldNode,
|
|
941
|
+
iterateChildFields(fieldNode, data, context.fragmentDefinitions, (childField, childTypeName, childFragmentKind, childFragmentName, childIndex) => {
|
|
428
942
|
promises.push(this._analyzeFieldNode(childField, {
|
|
429
943
|
cacheability,
|
|
430
944
|
entityData,
|
|
@@ -435,13 +949,13 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
435
949
|
requestFieldPath,
|
|
436
950
|
requestFieldPathData,
|
|
437
951
|
typeName: childTypeName
|
|
438
|
-
}, {
|
|
439
|
-
|
|
952
|
+
}, {
|
|
953
|
+
...cachedResponseData,
|
|
954
|
+
data: getDataValue(cachedResponseData.data, propNameOrIndex)
|
|
440
955
|
}, options, context));
|
|
441
956
|
});
|
|
442
957
|
await Promise.all(promises);
|
|
443
958
|
}
|
|
444
|
-
|
|
445
959
|
_buildCacheMetadata({
|
|
446
960
|
ast
|
|
447
961
|
}, {
|
|
@@ -452,59 +966,49 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
452
966
|
data,
|
|
453
967
|
...otherProps
|
|
454
968
|
}, context);
|
|
455
|
-
|
|
456
969
|
const queryNode = getOperationDefinitions(ast, context.operation)[0];
|
|
970
|
+
if (!queryNode) {
|
|
971
|
+
return cacheMetadata;
|
|
972
|
+
}
|
|
457
973
|
const fieldsAndTypeNames = getChildFields(queryNode);
|
|
458
|
-
|
|
459
974
|
if (!fieldsAndTypeNames) {
|
|
460
975
|
return cacheMetadata;
|
|
461
976
|
}
|
|
462
|
-
|
|
463
|
-
fieldsAndTypeNames.forEach(({
|
|
977
|
+
for (const {
|
|
464
978
|
fieldNode
|
|
465
|
-
})
|
|
979
|
+
} of fieldsAndTypeNames) this._setFieldCacheability(fieldNode, {
|
|
466
980
|
requestFieldPath: context.operation
|
|
467
981
|
}, {
|
|
468
982
|
cacheMetadata,
|
|
469
983
|
data
|
|
470
|
-
}, options, context)
|
|
984
|
+
}, options, context);
|
|
471
985
|
return cacheMetadata;
|
|
472
986
|
}
|
|
473
|
-
|
|
474
987
|
async _cacheResponse(requestData, updatedRequestData, rawResponseData, options, context) {
|
|
475
988
|
const normalizedResponseData = normalizePatchResponseData(rawResponseData, context);
|
|
476
989
|
let responseDataForCaching = normalizedResponseData;
|
|
477
|
-
|
|
478
990
|
if (isNotLastResponseChunk(rawResponseData, context)) {
|
|
479
991
|
this._setResponseChunksAwaitingCaching(normalizedResponseData, context);
|
|
480
|
-
|
|
481
992
|
responseDataForCaching = undefined;
|
|
482
993
|
}
|
|
483
|
-
|
|
484
994
|
if (isLastResponseChunk(rawResponseData, context)) {
|
|
485
995
|
responseDataForCaching = this._retrieveResponseDataForCaching(normalizedResponseData, context);
|
|
486
996
|
}
|
|
487
|
-
|
|
488
997
|
const dataCaching = [];
|
|
489
|
-
|
|
490
998
|
if (responseDataForCaching) {
|
|
491
999
|
const {
|
|
492
1000
|
data
|
|
493
1001
|
} = responseDataForCaching;
|
|
494
|
-
|
|
495
1002
|
const cacheMetadata = this._buildCacheMetadata(requestData, responseDataForCaching, options, context);
|
|
496
|
-
|
|
497
1003
|
dataCaching.push(this._setEntityAndRequestFieldPathCacheEntries(requestData, {
|
|
498
1004
|
cacheMetadata,
|
|
499
|
-
entityData:
|
|
500
|
-
requestFieldPathData:
|
|
1005
|
+
entityData: cloneDeep(data),
|
|
1006
|
+
requestFieldPathData: cloneDeep(data)
|
|
501
1007
|
}, options, context));
|
|
502
1008
|
let queryCacheMetadata;
|
|
503
1009
|
let queryData;
|
|
504
|
-
|
|
505
|
-
if (context.operation === QUERY) {
|
|
1010
|
+
if (context.operation === OperationTypeNode.QUERY) {
|
|
506
1011
|
let partialQueryResponse;
|
|
507
|
-
|
|
508
1012
|
if (context.queryFiltered && updatedRequestData) {
|
|
509
1013
|
dataCaching.push(this._setQueryResponseCacheEntry(updatedRequestData.hash, {
|
|
510
1014
|
cacheMetadata,
|
|
@@ -512,7 +1016,6 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
512
1016
|
}, options, context));
|
|
513
1017
|
partialQueryResponse = this._getPartialQueryResponse(requestData.hash);
|
|
514
1018
|
}
|
|
515
|
-
|
|
516
1019
|
queryCacheMetadata = CacheManager._mergeResponseCacheMetadata(cacheMetadata, partialQueryResponse);
|
|
517
1020
|
queryData = this._mergeResponseData(data, partialQueryResponse);
|
|
518
1021
|
dataCaching.push(this._setQueryResponseCacheEntry(requestData.hash, {
|
|
@@ -520,11 +1023,9 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
520
1023
|
data: queryData
|
|
521
1024
|
}, options, context));
|
|
522
1025
|
}
|
|
523
|
-
|
|
524
1026
|
if (options.awaitDataCaching) {
|
|
525
1027
|
await Promise.all(dataCaching);
|
|
526
1028
|
}
|
|
527
|
-
|
|
528
1029
|
if (isNotResponseChunk(normalizedResponseData, context) && queryCacheMetadata && queryData) {
|
|
529
1030
|
return {
|
|
530
1031
|
cacheMetadata: queryCacheMetadata,
|
|
@@ -532,7 +1033,6 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
532
1033
|
};
|
|
533
1034
|
}
|
|
534
1035
|
}
|
|
535
|
-
|
|
536
1036
|
const {
|
|
537
1037
|
data,
|
|
538
1038
|
hasNext,
|
|
@@ -545,30 +1045,24 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
545
1045
|
paths
|
|
546
1046
|
};
|
|
547
1047
|
}
|
|
548
|
-
|
|
549
1048
|
async _checkCacheEntry(cacheType, hash, options, context) {
|
|
550
1049
|
try {
|
|
551
1050
|
const cacheability = await this._hasCacheEntry(cacheType, hash);
|
|
552
|
-
|
|
553
1051
|
if (!cacheability || !CacheManager._isValid(cacheability)) {
|
|
554
1052
|
return false;
|
|
555
1053
|
}
|
|
556
|
-
|
|
557
1054
|
const entry = await this._getCacheEntry(cacheType, hash, options, context);
|
|
558
|
-
|
|
559
|
-
if (_isUndefined(entry)) {
|
|
1055
|
+
if (isUndefined(entry)) {
|
|
560
1056
|
return false;
|
|
561
1057
|
}
|
|
562
|
-
|
|
563
1058
|
return {
|
|
564
1059
|
cacheability,
|
|
565
1060
|
entry
|
|
566
1061
|
};
|
|
567
|
-
} catch
|
|
1062
|
+
} catch {
|
|
568
1063
|
return false;
|
|
569
1064
|
}
|
|
570
1065
|
}
|
|
571
|
-
|
|
572
1066
|
_createCacheMetadata({
|
|
573
1067
|
_cacheMetadata,
|
|
574
1068
|
headers
|
|
@@ -582,71 +1076,47 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
582
1076
|
headers
|
|
583
1077
|
});
|
|
584
1078
|
cacheMetadata.set(operation, cacheability);
|
|
585
|
-
|
|
586
1079
|
if (_cacheMetadata) {
|
|
587
1080
|
rehydrateCacheMetadata(_cacheMetadata, cacheMetadata);
|
|
588
1081
|
}
|
|
589
|
-
|
|
590
1082
|
return cacheMetadata;
|
|
591
1083
|
}
|
|
592
|
-
|
|
593
1084
|
async _getCacheEntry(cacheType, hash, _options, _context) {
|
|
594
|
-
|
|
595
|
-
return await this._cache.get(`${cacheType}::${hash}`);
|
|
596
|
-
} catch (errors) {
|
|
597
|
-
return Promise.reject(errors);
|
|
598
|
-
}
|
|
1085
|
+
return this._cache.get(`${cacheType}::${hash}`);
|
|
599
1086
|
}
|
|
600
|
-
|
|
601
1087
|
_getPartialQueryResponse(hash) {
|
|
602
1088
|
const partialQueryResponse = this._partialQueryResponses.get(hash);
|
|
603
|
-
|
|
604
1089
|
this._partialQueryResponses.delete(hash);
|
|
605
|
-
|
|
606
1090
|
return partialQueryResponse;
|
|
607
1091
|
}
|
|
608
|
-
|
|
609
1092
|
async _hasCacheEntry(cacheType, hash) {
|
|
610
1093
|
try {
|
|
611
1094
|
return await this._cache.has(`${cacheType}::${hash}`);
|
|
612
|
-
} catch
|
|
1095
|
+
} catch {
|
|
613
1096
|
return false;
|
|
614
1097
|
}
|
|
615
1098
|
}
|
|
616
|
-
|
|
617
1099
|
_isFieldEntity(fieldData, {
|
|
618
1100
|
isEntity,
|
|
619
1101
|
possibleTypes
|
|
620
1102
|
}) {
|
|
621
|
-
if (!
|
|
1103
|
+
if (!isPlainObject(fieldData) || !(this._typeIDKey in fieldData)) {
|
|
622
1104
|
return false;
|
|
623
1105
|
}
|
|
624
|
-
|
|
625
1106
|
if (isEntity) {
|
|
626
1107
|
return true;
|
|
627
1108
|
}
|
|
628
|
-
|
|
629
|
-
if (!possibleTypes.length) {
|
|
1109
|
+
if (possibleTypes.length === 0) {
|
|
630
1110
|
return false;
|
|
631
1111
|
}
|
|
632
|
-
|
|
633
1112
|
return possibleTypes.some(type => type.typeName === fieldData.__typename);
|
|
634
1113
|
}
|
|
635
|
-
|
|
636
|
-
_mergeObjects(obj, src) {
|
|
637
|
-
return mergeObjects(obj, src, (_key, val) => {
|
|
638
|
-
return _isPlainObject(val) && val[this._typeIDKey] ? val[this._typeIDKey] : undefined;
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
|
|
642
1114
|
_mergeResponseData(responseData, partialQueryResponse) {
|
|
643
1115
|
if (!partialQueryResponse) {
|
|
644
1116
|
return responseData;
|
|
645
1117
|
}
|
|
646
|
-
|
|
647
|
-
return this._mergeObjects(partialQueryResponse.data, responseData);
|
|
1118
|
+
return mergeDataSets(partialQueryResponse.data, responseData, this._typeIDKey);
|
|
648
1119
|
}
|
|
649
|
-
|
|
650
1120
|
async _parseEntityAndRequestFieldPathCacheEntryData(field, ancestorKeysAndPaths, {
|
|
651
1121
|
cacheMetadata,
|
|
652
1122
|
entityData,
|
|
@@ -658,16 +1128,12 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
658
1128
|
requestFieldPath,
|
|
659
1129
|
responseDataPath
|
|
660
1130
|
} = keysAndPaths;
|
|
661
|
-
|
|
662
|
-
const fieldData = _get(requestFieldPathData, responseDataPath);
|
|
663
|
-
|
|
1131
|
+
const fieldData = get(requestFieldPathData, responseDataPath);
|
|
664
1132
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
665
|
-
|
|
666
|
-
if (!_isObjectLike(fieldData) && !(fieldTypeInfo !== null && fieldTypeInfo !== void 0 && fieldTypeInfo.hasDirectives)) {
|
|
1133
|
+
if (!isObjectLike(fieldData) && !fieldTypeInfo?.hasDirectives) {
|
|
667
1134
|
return;
|
|
668
1135
|
}
|
|
669
|
-
|
|
670
|
-
if (_isObjectLike(fieldData)) {
|
|
1136
|
+
if (isObjectLike(fieldData)) {
|
|
671
1137
|
const promises = [];
|
|
672
1138
|
iterateChildFields(field, fieldData, context.fragmentDefinitions, (childField, _typeName, _fragmentKind, _fragmentName, childIndex) => {
|
|
673
1139
|
promises.push(this._parseEntityAndRequestFieldPathCacheEntryData(childField, {
|
|
@@ -683,14 +1149,12 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
683
1149
|
});
|
|
684
1150
|
await Promise.all(promises);
|
|
685
1151
|
}
|
|
686
|
-
|
|
687
1152
|
await this._setEntityAndRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
688
1153
|
cacheMetadata,
|
|
689
1154
|
entityData,
|
|
690
1155
|
requestFieldPathData
|
|
691
1156
|
}, options, context);
|
|
692
1157
|
}
|
|
693
|
-
|
|
694
1158
|
async _retrieveCachedEntityData(validTypeIDValue, {
|
|
695
1159
|
possibleTypes,
|
|
696
1160
|
typeName
|
|
@@ -699,7 +1163,6 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
699
1163
|
const checkResults = await Promise.all(typeNames.map(name => this._checkCacheEntry(DATA_ENTITIES, `${name}::${validTypeIDValue}`, options, context)));
|
|
700
1164
|
const validResults = checkResults.filter(result => !!result);
|
|
701
1165
|
let validResult;
|
|
702
|
-
|
|
703
1166
|
if (validResults.length === 1) {
|
|
704
1167
|
validResult = validResults[0];
|
|
705
1168
|
} else if (validResults.length > 1) {
|
|
@@ -712,13 +1175,11 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
712
1175
|
cacheability: validResults[0].cacheability,
|
|
713
1176
|
entry: validResults.reduce((obj, {
|
|
714
1177
|
entry
|
|
715
|
-
}) =>
|
|
1178
|
+
}) => mergeDataSets(obj, entry, this._typeIDKey), {})
|
|
716
1179
|
};
|
|
717
1180
|
}
|
|
718
|
-
|
|
719
|
-
return validResult || {};
|
|
1181
|
+
return validResult ?? {};
|
|
720
1182
|
}
|
|
721
|
-
|
|
722
1183
|
async _retrieveCachedParentNodeData({
|
|
723
1184
|
entityData: ancestorEntityData,
|
|
724
1185
|
requestFieldPathData: ancestorRequestFieldPathData
|
|
@@ -727,49 +1188,31 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
727
1188
|
propNameOrIndex,
|
|
728
1189
|
requestFieldCacheKey
|
|
729
1190
|
}, fieldTypeInfo, options, context) {
|
|
730
|
-
var _entityData;
|
|
731
|
-
|
|
732
1191
|
let entityData = CacheManager._getFieldDataFromAncestor(ancestorEntityData, propNameOrIndex);
|
|
733
|
-
|
|
734
1192
|
let requestFieldPathData = CacheManager._getFieldDataFromAncestor(ancestorRequestFieldPathData, propNameOrIndex);
|
|
735
|
-
|
|
736
1193
|
let cacheability;
|
|
737
|
-
|
|
738
1194
|
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
739
1195
|
const {
|
|
740
1196
|
cacheability: entryCacheability,
|
|
741
1197
|
entry
|
|
742
1198
|
} = await this._retrieveCachedRequestFieldPathData(hashedRequestFieldCacheKey, requestFieldCacheKey, options, context);
|
|
743
|
-
|
|
744
|
-
if (entry) {
|
|
745
|
-
requestFieldPathData = this._mergeObjects(requestFieldPathData, entry);
|
|
746
|
-
}
|
|
747
|
-
|
|
1199
|
+
requestFieldPathData = combineDataSets(requestFieldPathData, entry, this._typeIDKey);
|
|
748
1200
|
if (entryCacheability) {
|
|
749
1201
|
cacheability = entryCacheability;
|
|
750
1202
|
}
|
|
751
1203
|
}
|
|
752
|
-
|
|
753
|
-
const validTypeIDValue = getValidTypeIDValue(requestFieldPathData, fieldTypeInfo, this._typeIDKey);
|
|
754
|
-
|
|
1204
|
+
const validTypeIDValue = getValidTypeIdValue(requestFieldPathData, fieldTypeInfo, this._typeIDKey);
|
|
755
1205
|
if (CacheManager._isNodeEntity(fieldTypeInfo) && validTypeIDValue) {
|
|
756
|
-
var _cacheability;
|
|
757
|
-
|
|
758
1206
|
const {
|
|
759
1207
|
cacheability: entryCacheability,
|
|
760
1208
|
entry
|
|
761
1209
|
} = await this._retrieveCachedEntityData(validTypeIDValue, fieldTypeInfo, options, context);
|
|
762
|
-
|
|
763
|
-
if (
|
|
764
|
-
entityData = this._mergeObjects(entityData, entry);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
if (entryCacheability && (!cacheability || entryCacheability.metadata.ttl > ((_cacheability = cacheability) === null || _cacheability === void 0 ? void 0 : _cacheability.metadata.ttl))) {
|
|
1210
|
+
entityData = combineDataSets(entityData, entry, this._typeIDKey);
|
|
1211
|
+
if (entryCacheability && (!cacheability || entryCacheability.metadata.ttl > cacheability.metadata.ttl)) {
|
|
768
1212
|
cacheability = entryCacheability;
|
|
769
1213
|
}
|
|
770
1214
|
}
|
|
771
|
-
|
|
772
|
-
const data = !_isUndefined(requestFieldPathData) || !_isUndefined(entityData) ? this._mergeObjects(requestFieldPathData, entityData) : (_entityData = entityData) !== null && _entityData !== void 0 ? _entityData : requestFieldPathData;
|
|
1215
|
+
const data = isEqual(entityData, requestFieldPathData) ? entityData : combineDataSets(entityData, requestFieldPathData, this._typeIDKey);
|
|
773
1216
|
return {
|
|
774
1217
|
cacheability,
|
|
775
1218
|
data,
|
|
@@ -777,13 +1220,12 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
777
1220
|
requestFieldPathData
|
|
778
1221
|
};
|
|
779
1222
|
}
|
|
780
|
-
|
|
781
1223
|
async _retrieveCachedRequestFieldPathData(hash, requestFieldCacheKey, options, context) {
|
|
782
|
-
return this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, {
|
|
1224
|
+
return (await this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, {
|
|
1225
|
+
...context,
|
|
783
1226
|
requestFieldCacheKey
|
|
784
|
-
}) || {};
|
|
1227
|
+
})) || {};
|
|
785
1228
|
}
|
|
786
|
-
|
|
787
1229
|
async _retrieveCachedResponseData({
|
|
788
1230
|
ast
|
|
789
1231
|
}, options, context) {
|
|
@@ -797,12 +1239,13 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
797
1239
|
fieldPathChecklist: new Map()
|
|
798
1240
|
};
|
|
799
1241
|
const queryNode = getOperationDefinitions(ast, context.operation)[0];
|
|
1242
|
+
if (!queryNode) {
|
|
1243
|
+
return cachedResponseData;
|
|
1244
|
+
}
|
|
800
1245
|
const fieldsAndTypeNames = getChildFields(queryNode);
|
|
801
|
-
|
|
802
1246
|
if (!fieldsAndTypeNames) {
|
|
803
1247
|
return cachedResponseData;
|
|
804
1248
|
}
|
|
805
|
-
|
|
806
1249
|
await Promise.all(fieldsAndTypeNames.map(({
|
|
807
1250
|
fieldNode
|
|
808
1251
|
}) => this._analyzeFieldNode(fieldNode, {
|
|
@@ -811,29 +1254,25 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
811
1254
|
cachedResponseData.fieldCount = CacheManager._countFieldPathChecklist(cachedResponseData.fieldPathChecklist);
|
|
812
1255
|
return cachedResponseData;
|
|
813
1256
|
}
|
|
814
|
-
|
|
815
1257
|
_retrieveResponseDataForCaching(normalizedResponseData, context) {
|
|
816
1258
|
const responseChunks = this._responseChunksAwaitingCaching.get(context.requestID);
|
|
817
|
-
|
|
818
1259
|
this._responseChunksAwaitingCaching.delete(context.requestID);
|
|
819
|
-
|
|
820
1260
|
return mergeResponseDataSets([...responseChunks, normalizedResponseData]);
|
|
821
1261
|
}
|
|
822
|
-
|
|
823
1262
|
async _setCacheEntry(cacheType, hash, value, cachemapOptions, _options, _context) {
|
|
824
1263
|
try {
|
|
825
|
-
await this._cache.set(`${cacheType}::${hash}`,
|
|
826
|
-
} catch
|
|
1264
|
+
await this._cache.set(`${cacheType}::${hash}`, cloneDeep(value), cachemapOptions);
|
|
1265
|
+
} catch {}
|
|
827
1266
|
}
|
|
828
|
-
|
|
829
1267
|
async _setEntityAndRequestFieldPathCacheEntries(requestData, responseData, options, context) {
|
|
830
1268
|
const operationNode = getOperationDefinitions(requestData.ast, context.operation)[0];
|
|
1269
|
+
if (!operationNode) {
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
831
1272
|
const fieldsAndTypeNames = getChildFields(operationNode);
|
|
832
|
-
|
|
833
1273
|
if (!fieldsAndTypeNames) {
|
|
834
1274
|
return;
|
|
835
1275
|
}
|
|
836
|
-
|
|
837
1276
|
await Promise.all(fieldsAndTypeNames.map(({
|
|
838
1277
|
fieldNode
|
|
839
1278
|
}) => {
|
|
@@ -842,7 +1281,6 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
842
1281
|
}, responseData, options, context);
|
|
843
1282
|
}));
|
|
844
1283
|
}
|
|
845
|
-
|
|
846
1284
|
async _setEntityAndRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
847
1285
|
cacheMetadata,
|
|
848
1286
|
entityData,
|
|
@@ -852,29 +1290,22 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
852
1290
|
requestFieldPath,
|
|
853
1291
|
responseDataPath
|
|
854
1292
|
} = keysAndPaths;
|
|
855
|
-
|
|
856
|
-
const fieldData = _get(entityData, responseDataPath);
|
|
857
|
-
|
|
1293
|
+
const fieldData = get(entityData, responseDataPath);
|
|
858
1294
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
859
1295
|
const cacheability = cacheMetadata.get(requestFieldPath);
|
|
860
|
-
|
|
861
|
-
if (_isUndefined(fieldData) || !fieldTypeInfo || !cacheability) {
|
|
1296
|
+
if (isUndefined(fieldData) || !fieldTypeInfo || !cacheability) {
|
|
862
1297
|
return;
|
|
863
1298
|
}
|
|
864
|
-
|
|
865
1299
|
const promises = [];
|
|
866
1300
|
promises.push(this._setRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
867
1301
|
cacheability,
|
|
868
1302
|
data: requestFieldPathData,
|
|
869
1303
|
fieldTypeInfo
|
|
870
1304
|
}, options, context));
|
|
871
|
-
|
|
872
1305
|
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
873
|
-
|
|
874
1306
|
if (!isEntity && fieldTypeInfo.hasArguments) {
|
|
875
|
-
|
|
1307
|
+
unset(entityData, responseDataPath);
|
|
876
1308
|
}
|
|
877
|
-
|
|
878
1309
|
if (isEntity) {
|
|
879
1310
|
promises.push(this._setEntityCacheEntry(keysAndPaths, {
|
|
880
1311
|
cacheability,
|
|
@@ -882,10 +1313,8 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
882
1313
|
fieldTypeInfo
|
|
883
1314
|
}, options, context));
|
|
884
1315
|
}
|
|
885
|
-
|
|
886
1316
|
await Promise.all(promises);
|
|
887
1317
|
}
|
|
888
|
-
|
|
889
1318
|
async _setEntityCacheEntry({
|
|
890
1319
|
responseDataPath
|
|
891
1320
|
}, {
|
|
@@ -893,28 +1322,23 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
893
1322
|
data,
|
|
894
1323
|
fieldTypeInfo
|
|
895
1324
|
}, options, context) {
|
|
896
|
-
let fieldData =
|
|
897
|
-
|
|
1325
|
+
let fieldData = get(data, responseDataPath);
|
|
898
1326
|
const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
|
|
899
|
-
const entityDataKey = `${fieldTypeName}::${fieldData[this._typeIDKey]}`;
|
|
1327
|
+
const entityDataKey = `${fieldTypeName}::${String(fieldData[this._typeIDKey])}`;
|
|
900
1328
|
const result = await this._checkCacheEntry(DATA_ENTITIES, entityDataKey, options, context);
|
|
901
|
-
|
|
902
1329
|
if (result) {
|
|
903
|
-
fieldData =
|
|
1330
|
+
fieldData = mergeDataSets(result.entry, fieldData, this._typeIDKey);
|
|
904
1331
|
}
|
|
905
|
-
|
|
906
1332
|
await this._setCacheEntry(DATA_ENTITIES, entityDataKey, fieldData, {
|
|
907
1333
|
cacheHeaders: {
|
|
908
1334
|
cacheControl: cacheability.printCacheControl()
|
|
909
1335
|
},
|
|
910
1336
|
tag: options.tag
|
|
911
1337
|
}, options, context);
|
|
912
|
-
|
|
913
|
-
_set(data, responseDataPath, {
|
|
1338
|
+
set(data, responseDataPath, {
|
|
914
1339
|
__cacheKey: `${DATA_ENTITIES}::${entityDataKey}`
|
|
915
1340
|
});
|
|
916
1341
|
}
|
|
917
|
-
|
|
918
1342
|
_setFieldCacheability(field, ancestorKeysAndPaths, {
|
|
919
1343
|
cacheMetadata,
|
|
920
1344
|
data
|
|
@@ -927,21 +1351,19 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
927
1351
|
requestFieldPath,
|
|
928
1352
|
responseDataPath
|
|
929
1353
|
} = keysAndPaths;
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1354
|
+
if (!isObjectLike(data)) {
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
const fieldData = get(data, responseDataPath);
|
|
933
1358
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
934
|
-
|
|
935
|
-
if (!_isObjectLike(fieldData) && !(fieldTypeInfo !== null && fieldTypeInfo !== void 0 && fieldTypeInfo.hasDirectives)) {
|
|
1359
|
+
if (!isObjectLike(fieldData) && !fieldTypeInfo?.hasDirectives) {
|
|
936
1360
|
return;
|
|
937
1361
|
}
|
|
938
|
-
|
|
939
1362
|
this._setFieldTypeCacheDirective(cacheMetadata, {
|
|
940
1363
|
ancestorRequestFieldPath,
|
|
941
1364
|
requestFieldPath
|
|
942
1365
|
}, context);
|
|
943
|
-
|
|
944
|
-
if (_isObjectLike(fieldData)) {
|
|
1366
|
+
if (isObjectLike(fieldData)) {
|
|
945
1367
|
iterateChildFields(field, fieldData, context.fragmentDefinitions, (childField, _typeName, _fragmentKind, _fragmentName, childIndex) => {
|
|
946
1368
|
this._setFieldCacheability(childField, {
|
|
947
1369
|
index: childIndex,
|
|
@@ -954,7 +1376,6 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
954
1376
|
});
|
|
955
1377
|
}
|
|
956
1378
|
}
|
|
957
|
-
|
|
958
1379
|
_setFieldTypeCacheDirective(cacheMetadata, {
|
|
959
1380
|
ancestorRequestFieldPath,
|
|
960
1381
|
requestFieldPath
|
|
@@ -965,32 +1386,25 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
965
1386
|
if (cacheMetadata.has(requestFieldPath)) {
|
|
966
1387
|
return;
|
|
967
1388
|
}
|
|
968
|
-
|
|
969
1389
|
const fieldTypeInfo = fieldTypeMap.get(requestFieldPath);
|
|
970
|
-
|
|
971
1390
|
if (fieldTypeInfo && this._typeCacheDirectives[fieldTypeInfo.typeName]) {
|
|
972
1391
|
const cacheability = new Cacheability({
|
|
973
1392
|
cacheControl: this._typeCacheDirectives[fieldTypeInfo.typeName]
|
|
974
1393
|
});
|
|
975
|
-
|
|
976
1394
|
CacheManager._setCacheMetadata(cacheMetadata, cacheability, requestFieldPath, operation);
|
|
977
1395
|
} else if (this._cascadeCacheControl && ancestorRequestFieldPath) {
|
|
978
1396
|
CacheManager._setCacheMetadata(cacheMetadata, cacheMetadata.get(ancestorRequestFieldPath), requestFieldPath, operation);
|
|
979
1397
|
}
|
|
980
1398
|
}
|
|
981
|
-
|
|
982
|
-
async _setPartialQueryResponse(hash, partialQueryResponse, _options, _context) {
|
|
1399
|
+
_setPartialQueryResponse(hash, partialQueryResponse, _options, _context) {
|
|
983
1400
|
this._partialQueryResponses.set(hash, partialQueryResponse);
|
|
984
1401
|
}
|
|
985
|
-
|
|
986
1402
|
async _setQueryResponseCacheEntry(hash, {
|
|
987
1403
|
cacheMetadata,
|
|
988
1404
|
data
|
|
989
1405
|
}, options, context) {
|
|
990
1406
|
const dehydratedCacheMetadata = dehydrateCacheMetadata(cacheMetadata);
|
|
991
|
-
|
|
992
1407
|
const cacheControl = CacheManager._getOperationCacheControl(cacheMetadata, context.operation);
|
|
993
|
-
|
|
994
1408
|
await this._setCacheEntry(QUERY_RESPONSES, hash, {
|
|
995
1409
|
cacheMetadata: dehydratedCacheMetadata,
|
|
996
1410
|
data
|
|
@@ -1001,7 +1415,6 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
1001
1415
|
tag: options.tag
|
|
1002
1416
|
}, options, context);
|
|
1003
1417
|
}
|
|
1004
|
-
|
|
1005
1418
|
async _setRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
1006
1419
|
cacheability,
|
|
1007
1420
|
data,
|
|
@@ -1012,61 +1425,51 @@ let CacheManager = (_dec = logCacheQuery(), _dec2 = logCacheEntry(), _dec3 = log
|
|
|
1012
1425
|
requestFieldCacheKey,
|
|
1013
1426
|
responseDataPath
|
|
1014
1427
|
} = keysAndPaths;
|
|
1015
|
-
|
|
1016
|
-
let fieldData = _get(data, responseDataPath);
|
|
1017
|
-
|
|
1428
|
+
let fieldData = get(data, responseDataPath);
|
|
1018
1429
|
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
1019
|
-
|
|
1020
1430
|
const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
var _field$selectionSet;
|
|
1024
|
-
|
|
1025
|
-
if (_isPlainObject(fieldData) && (_field$selectionSet = field.selectionSet) !== null && _field$selectionSet !== void 0 && _field$selectionSet.selections) {
|
|
1431
|
+
if (context.operation === OperationTypeNode.QUERY && (isEntity || hasArgsOrDirectives)) {
|
|
1432
|
+
if (isPlainObject(fieldData) && field.selectionSet?.selections) {
|
|
1026
1433
|
fieldData = filterOutPropsWithArgsOrDirectives(fieldData, field.selectionSet.selections, keysAndPaths, context);
|
|
1027
1434
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1435
|
+
const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, {
|
|
1436
|
+
...context,
|
|
1030
1437
|
requestFieldCacheKey
|
|
1031
1438
|
});
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
fieldData = this._mergeObjects(result.entry, fieldData);
|
|
1439
|
+
if (result && isObjectLike(result.entry) && isObjectLike(fieldData)) {
|
|
1440
|
+
fieldData = mergeDataSets(result.entry, fieldData, this._typeIDKey);
|
|
1035
1441
|
}
|
|
1036
|
-
|
|
1037
1442
|
await this._setCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, fieldData, {
|
|
1038
1443
|
cacheHeaders: {
|
|
1039
1444
|
cacheControl: cacheability.printCacheControl()
|
|
1040
1445
|
},
|
|
1041
1446
|
tag: options.tag
|
|
1042
|
-
}, options, {
|
|
1447
|
+
}, options, {
|
|
1448
|
+
...context,
|
|
1043
1449
|
requestFieldCacheKey
|
|
1044
1450
|
});
|
|
1045
|
-
|
|
1046
1451
|
if (hasChildFields(field, {
|
|
1047
1452
|
fragmentDefinitions: context.fragmentDefinitions
|
|
1048
1453
|
})) {
|
|
1049
1454
|
if (isEntity) {
|
|
1050
|
-
|
|
1455
|
+
set(data, responseDataPath, {
|
|
1051
1456
|
__cacheKey: `${REQUEST_FIELD_PATHS}::${hashedRequestFieldCacheKey}`
|
|
1052
1457
|
});
|
|
1053
1458
|
} else {
|
|
1054
|
-
|
|
1459
|
+
unset(data, responseDataPath);
|
|
1055
1460
|
}
|
|
1056
1461
|
}
|
|
1057
1462
|
}
|
|
1058
1463
|
}
|
|
1059
|
-
|
|
1060
1464
|
_setResponseChunksAwaitingCaching(normalizedResponseData, context) {
|
|
1061
1465
|
const responseChunks = this._responseChunksAwaitingCaching.get(context.requestID);
|
|
1062
|
-
|
|
1063
1466
|
if (responseChunks) {
|
|
1064
1467
|
this._responseChunksAwaitingCaching.set(context.requestID, [...responseChunks, normalizedResponseData]);
|
|
1065
1468
|
} else {
|
|
1066
1469
|
this._responseChunksAwaitingCaching.set(context.requestID, [normalizedResponseData]);
|
|
1067
1470
|
}
|
|
1068
1471
|
}
|
|
1069
|
-
|
|
1070
1472
|
}, (_applyDecoratedDescriptor(_class.prototype, "_getCacheEntry", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "_getCacheEntry"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_setCacheEntry", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "_setCacheEntry"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_setPartialQueryResponse", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "_setPartialQueryResponse"), _class.prototype)), _class));
|
|
1071
|
-
|
|
1072
|
-
|
|
1473
|
+
|
|
1474
|
+
export { CacheManager };
|
|
1475
|
+
//# sourceMappingURL=index.mjs.map
|