@graphql-box/cache-manager 2.1.4 → 2.3.1
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/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/production.analysis.txt +129 -17
- package/lib/main/debug/log-cache-entry/index.js.map +1 -1
- package/lib/main/debug/log-partial-compiled/index.js.map +1 -1
- package/lib/main/helpers/buildKeysAndPaths.js +73 -0
- package/lib/main/helpers/buildKeysAndPaths.js.map +1 -0
- package/lib/main/helpers/checkFieldPathChecklist.js +40 -0
- package/lib/main/helpers/checkFieldPathChecklist.js.map +1 -0
- package/lib/main/helpers/createFragmentSpreadChecklist.js +28 -0
- package/lib/main/helpers/createFragmentSpreadChecklist.js.map +1 -0
- package/lib/main/helpers/filterField.js +97 -0
- package/lib/main/helpers/filterField.js.map +1 -0
- package/lib/main/helpers/filterFragmentDefinitions.js +50 -0
- package/lib/main/helpers/filterFragmentDefinitions.js.map +1 -0
- package/lib/main/helpers/filterFragmentSpreads.js +37 -0
- package/lib/main/helpers/filterFragmentSpreads.js.map +1 -0
- package/lib/main/helpers/filterIDsAndTypeNames.js +47 -0
- package/lib/main/helpers/filterIDsAndTypeNames.js.map +1 -0
- package/lib/main/helpers/filterInlineFragments.js +42 -0
- package/lib/main/helpers/filterInlineFragments.js.map +1 -0
- package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js +39 -0
- package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -0
- package/lib/main/helpers/filterQuery.js +59 -0
- package/lib/main/helpers/filterQuery.js.map +1 -0
- package/lib/main/helpers/normalizeResponseData.js +24 -0
- package/lib/main/helpers/normalizeResponseData.js.map +1 -0
- package/lib/main/helpers/validTypeIDValue.js +20 -0
- package/lib/main/helpers/validTypeIDValue.js.map +1 -0
- package/lib/main/main/index.js +495 -488
- package/lib/main/main/index.js.map +1 -1
- package/lib/module/debug/log-cache-entry/index.js.map +1 -1
- package/lib/module/debug/log-partial-compiled/index.js.map +1 -1
- package/lib/module/helpers/buildKeysAndPaths.js +54 -0
- package/lib/module/helpers/buildKeysAndPaths.js.map +1 -0
- package/lib/module/helpers/checkFieldPathChecklist.js +31 -0
- package/lib/module/helpers/checkFieldPathChecklist.js.map +1 -0
- package/lib/module/helpers/createFragmentSpreadChecklist.js +15 -0
- package/lib/module/helpers/createFragmentSpreadChecklist.js.map +1 -0
- package/lib/module/helpers/filterField.js +81 -0
- package/lib/module/helpers/filterField.js.map +1 -0
- package/lib/module/helpers/filterFragmentDefinitions.js +39 -0
- package/lib/module/helpers/filterFragmentDefinitions.js.map +1 -0
- package/lib/module/helpers/filterFragmentSpreads.js +23 -0
- package/lib/module/helpers/filterFragmentSpreads.js.map +1 -0
- package/lib/module/helpers/filterIDsAndTypeNames.js +36 -0
- package/lib/module/helpers/filterIDsAndTypeNames.js.map +1 -0
- package/lib/module/helpers/filterInlineFragments.js +32 -0
- package/lib/module/helpers/filterInlineFragments.js.map +1 -0
- package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js +25 -0
- package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js.map +1 -0
- package/lib/module/helpers/filterQuery.js +43 -0
- package/lib/module/helpers/filterQuery.js.map +1 -0
- package/lib/module/helpers/normalizeResponseData.js +12 -0
- package/lib/module/helpers/normalizeResponseData.js.map +1 -0
- package/lib/module/helpers/validTypeIDValue.js +8 -0
- package/lib/module/helpers/validTypeIDValue.js.map +1 -0
- package/lib/module/main/index.js +492 -486
- package/lib/module/main/index.js.map +1 -1
- package/lib/types/debug/log-cache-entry/index.d.ts.map +1 -1
- package/lib/types/debug/log-cache-query/index.d.ts.map +1 -1
- package/lib/types/debug/log-partial-compiled/index.d.ts.map +1 -1
- package/lib/types/defs/index.d.ts +19 -9
- package/lib/types/defs/index.d.ts.map +1 -1
- package/lib/types/helpers/buildKeysAndPaths.d.ts +10 -0
- package/lib/types/helpers/buildKeysAndPaths.d.ts.map +1 -0
- package/lib/types/helpers/checkFieldPathChecklist.d.ts +4 -0
- package/lib/types/helpers/checkFieldPathChecklist.d.ts.map +1 -0
- package/lib/types/helpers/createFragmentSpreadChecklist.d.ts +11 -0
- package/lib/types/helpers/createFragmentSpreadChecklist.d.ts.map +1 -0
- package/lib/types/helpers/filterField.d.ts +6 -0
- package/lib/types/helpers/filterField.d.ts.map +1 -0
- package/lib/types/helpers/filterFragmentDefinitions.d.ts +10 -0
- package/lib/types/helpers/filterFragmentDefinitions.d.ts.map +1 -0
- package/lib/types/helpers/filterFragmentSpreads.d.ts +6 -0
- package/lib/types/helpers/filterFragmentSpreads.d.ts.map +1 -0
- package/lib/types/helpers/filterIDsAndTypeNames.d.ts +5 -0
- package/lib/types/helpers/filterIDsAndTypeNames.d.ts.map +1 -0
- package/lib/types/helpers/filterInlineFragments.d.ts +5 -0
- package/lib/types/helpers/filterInlineFragments.d.ts.map +1 -0
- package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts +6 -0
- package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +1 -0
- package/lib/types/helpers/filterQuery.d.ts +5 -0
- package/lib/types/helpers/filterQuery.d.ts.map +1 -0
- package/lib/types/helpers/normalizeResponseData.d.ts +11 -0
- package/lib/types/helpers/normalizeResponseData.d.ts.map +1 -0
- package/lib/types/helpers/validTypeIDValue.d.ts +3 -0
- package/lib/types/helpers/validTypeIDValue.d.ts.map +1 -0
- package/lib/types/main/index.d.ts +15 -22
- package/lib/types/main/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__snapshots__/index.test.ts.snap +17466 -7185
- package/src/debug/log-cache-entry/index.ts +1 -1
- package/src/debug/log-partial-compiled/index.ts +1 -1
- package/src/defs/index.ts +18 -10
- package/src/helpers/buildKeysAndPaths.ts +71 -0
- package/src/helpers/checkFieldPathChecklist.ts +21 -0
- package/src/helpers/createFragmentSpreadChecklist.ts +17 -0
- package/src/helpers/filterField.ts +73 -0
- package/src/helpers/filterFragmentDefinitions.ts +40 -0
- package/src/helpers/filterFragmentSpreads.ts +28 -0
- package/src/helpers/filterIDsAndTypeNames.ts +31 -0
- package/src/helpers/filterInlineFragments.ts +29 -0
- package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +30 -0
- package/src/helpers/filterQuery.ts +38 -0
- package/src/helpers/normalizeResponseData.ts +10 -0
- package/src/helpers/validTypeIDValue.ts +11 -0
- package/src/index.test.ts +179 -3
- package/src/main/index.ts +540 -524
package/lib/main/main/index.js
CHANGED
|
@@ -24,19 +24,19 @@ var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
|
24
24
|
|
|
25
25
|
var _isObjectLike2 = _interopRequireDefault(require("lodash/isObjectLike"));
|
|
26
26
|
|
|
27
|
-
var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
|
|
28
|
-
|
|
29
27
|
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
|
|
30
28
|
|
|
31
29
|
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
32
30
|
|
|
33
31
|
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
34
32
|
|
|
33
|
+
var _assign2 = _interopRequireDefault(require("lodash/assign"));
|
|
34
|
+
|
|
35
35
|
var _core = require("@graphql-box/core");
|
|
36
36
|
|
|
37
37
|
var _helpers = require("@graphql-box/helpers");
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var _cacheability2 = _interopRequireDefault(require("cacheability"));
|
|
40
40
|
|
|
41
41
|
var _graphql = require("graphql");
|
|
42
42
|
|
|
@@ -44,8 +44,18 @@ var _consts = require("../consts");
|
|
|
44
44
|
|
|
45
45
|
var _debug = require("../debug");
|
|
46
46
|
|
|
47
|
+
var _buildKeysAndPaths = require("../helpers/buildKeysAndPaths");
|
|
48
|
+
|
|
47
49
|
var _deriveOpCacheability = _interopRequireDefault(require("../helpers/deriveOpCacheability"));
|
|
48
50
|
|
|
51
|
+
var _filterOutPropsWithArgsOrDirectives = _interopRequireDefault(require("../helpers/filterOutPropsWithArgsOrDirectives"));
|
|
52
|
+
|
|
53
|
+
var _filterQuery = _interopRequireDefault(require("../helpers/filterQuery"));
|
|
54
|
+
|
|
55
|
+
var _normalizeResponseData = _interopRequireDefault(require("../helpers/normalizeResponseData"));
|
|
56
|
+
|
|
57
|
+
var _validTypeIDValue = require("../helpers/validTypeIDValue");
|
|
58
|
+
|
|
49
59
|
var _dec, _dec2, _dec3, _class;
|
|
50
60
|
|
|
51
61
|
let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCacheEntry)(), _dec3 = (0, _debug.logPartialCompiled)(), (_class = class CacheManager {
|
|
@@ -61,85 +71,11 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
61
71
|
errors.push(new TypeError(message));
|
|
62
72
|
}
|
|
63
73
|
|
|
64
|
-
if (errors.length)
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static _analyzeLeafField(field, cachedAncestorFieldData, {
|
|
69
|
-
data,
|
|
70
|
-
fieldPathChecklist
|
|
71
|
-
}, _options, _context) {
|
|
72
|
-
const keysAndPaths = CacheManager._getFieldKeysAndPaths(field, cachedAncestorFieldData);
|
|
73
|
-
|
|
74
|
-
const {
|
|
75
|
-
propNameOrIndex,
|
|
76
|
-
requestFieldPath
|
|
77
|
-
} = keysAndPaths;
|
|
78
|
-
const {
|
|
79
|
-
dataEntityData,
|
|
80
|
-
requestFieldPathData,
|
|
81
|
-
typeName
|
|
82
|
-
} = cachedAncestorFieldData;
|
|
83
|
-
|
|
84
|
-
const cachedFieldData = CacheManager._getFieldDataFromAncestor(dataEntityData, propNameOrIndex) || CacheManager._getFieldDataFromAncestor(requestFieldPathData, propNameOrIndex);
|
|
85
|
-
|
|
86
|
-
const typeNames = {
|
|
87
|
-
dataTypeName: (dataEntityData === null || dataEntityData === void 0 ? void 0 : dataEntityData.__typename) || (requestFieldPathData === null || requestFieldPathData === void 0 ? void 0 : requestFieldPathData.__typename),
|
|
88
|
-
fieldTypeName: typeName
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
CacheManager._setFieldPathChecklist(fieldPathChecklist, {
|
|
92
|
-
data: cachedFieldData
|
|
93
|
-
}, requestFieldPath, typeNames);
|
|
94
|
-
|
|
95
|
-
CacheManager._setCachedData(data, {
|
|
96
|
-
data: cachedFieldData
|
|
97
|
-
}, propNameOrIndex);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static _buildKey(key, path) {
|
|
101
|
-
const paths = [];
|
|
102
|
-
if (path.length) paths.push(path);
|
|
103
|
-
paths.push(key);
|
|
104
|
-
return paths.join(".");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
static _buildRequestFieldCacheKey(name, requestFieldCacheKey, args, directives, index) {
|
|
108
|
-
let key = `${(0, _isNumber2.default)(index) ? index : name}`;
|
|
109
|
-
if (args) key = `${key}(${JSON.stringify(args)})`;
|
|
110
|
-
if (directives) key = `${key}(${JSON.stringify(directives)})`;
|
|
111
|
-
return CacheManager._buildKey(key, requestFieldCacheKey);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
static _checkFieldPathChecklist(fieldPathChecklistValues, fieldTypeName) {
|
|
115
|
-
if (!fieldPathChecklistValues || !fieldPathChecklistValues.length) {
|
|
116
|
-
return {
|
|
117
|
-
hasData: false,
|
|
118
|
-
typeUnused: !!fieldTypeName
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (fieldPathChecklistValues.length === 1) {
|
|
123
|
-
const {
|
|
124
|
-
hasData,
|
|
125
|
-
typeName
|
|
126
|
-
} = fieldPathChecklistValues[0];
|
|
127
|
-
const typeUnused = !typeName ? undefined : typeName !== fieldTypeName;
|
|
128
|
-
return {
|
|
129
|
-
hasData,
|
|
130
|
-
typeUnused
|
|
131
|
-
};
|
|
74
|
+
if (errors.length) {
|
|
75
|
+
return Promise.reject(errors);
|
|
132
76
|
}
|
|
133
77
|
|
|
134
|
-
return
|
|
135
|
-
hasData: fieldPathChecklistValues.some(({
|
|
136
|
-
hasData,
|
|
137
|
-
typeName
|
|
138
|
-
}) => typeName === fieldTypeName && hasData),
|
|
139
|
-
typeUnused: !fieldPathChecklistValues.every(({
|
|
140
|
-
typeName
|
|
141
|
-
}) => typeName === fieldTypeName)
|
|
142
|
-
};
|
|
78
|
+
return new CacheManager(options);
|
|
143
79
|
}
|
|
144
80
|
|
|
145
81
|
static _countFieldPathChecklist(fieldPathChecklist) {
|
|
@@ -158,49 +94,25 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
158
94
|
}
|
|
159
95
|
|
|
160
96
|
static _getFieldDataFromAncestor(ancestorFieldData, propNameOrIndex) {
|
|
161
|
-
return (0, _isObjectLike2.default)(ancestorFieldData) ? ancestorFieldData[propNameOrIndex] : undefined;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
static _getFieldKeysAndPaths(field, options) {
|
|
165
|
-
const {
|
|
166
|
-
index,
|
|
167
|
-
requestFieldCacheKey = "",
|
|
168
|
-
requestFieldPath = "",
|
|
169
|
-
responseDataPath = ""
|
|
170
|
-
} = options;
|
|
171
|
-
const name = (0, _helpers.getName)(field);
|
|
172
|
-
|
|
173
|
-
const updatedRequestFieldCacheKey = CacheManager._buildRequestFieldCacheKey(name, requestFieldCacheKey, (0, _helpers.getArguments)(field), (0, _helpers.getDirectives)(field), index);
|
|
174
|
-
|
|
175
|
-
const fieldAliasOrName = (0, _helpers.getAlias)(field) || name;
|
|
176
|
-
const updatedRequestFieldPath = (0, _isNumber2.default)(index) ? requestFieldPath : CacheManager._buildKey(fieldAliasOrName, requestFieldPath);
|
|
177
|
-
const propNameOrIndex = (0, _isNumber2.default)(index) ? index : fieldAliasOrName;
|
|
178
|
-
|
|
179
|
-
const updatedResponseDataPath = CacheManager._buildKey(propNameOrIndex, responseDataPath);
|
|
180
|
-
|
|
181
|
-
return {
|
|
182
|
-
hashedRequestFieldCacheKey: (0, _helpers.hashRequest)(updatedRequestFieldCacheKey),
|
|
183
|
-
propNameOrIndex,
|
|
184
|
-
requestFieldCacheKey: updatedRequestFieldCacheKey,
|
|
185
|
-
requestFieldPath: updatedRequestFieldPath,
|
|
186
|
-
responseDataPath: updatedResponseDataPath
|
|
187
|
-
};
|
|
97
|
+
return (0, _isObjectLike2.default)(ancestorFieldData) ? (0, _cloneDeep2.default)(ancestorFieldData[propNameOrIndex]) : undefined;
|
|
188
98
|
}
|
|
189
99
|
|
|
190
100
|
static _getOperationCacheControl(cacheMetadata, operation) {
|
|
191
101
|
const defaultCacheControl = _consts.HEADER_NO_CACHE;
|
|
192
|
-
|
|
102
|
+
|
|
103
|
+
if (!cacheMetadata) {
|
|
104
|
+
return defaultCacheControl;
|
|
105
|
+
}
|
|
106
|
+
|
|
193
107
|
const cacheability = cacheMetadata.get(operation);
|
|
194
108
|
return cacheability ? cacheability.printCacheControl() : defaultCacheControl;
|
|
195
109
|
}
|
|
196
110
|
|
|
197
|
-
static
|
|
198
|
-
if (!
|
|
199
|
-
|
|
200
|
-
|
|
111
|
+
static _isNodeEntity(fieldTypeInfo) {
|
|
112
|
+
if (!fieldTypeInfo) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
201
115
|
|
|
202
|
-
static _isDataEntity(fieldTypeInfo) {
|
|
203
|
-
if (!fieldTypeInfo) return false;
|
|
204
116
|
const {
|
|
205
117
|
isEntity,
|
|
206
118
|
possibleTypes
|
|
@@ -208,8 +120,8 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
208
120
|
return isEntity || possibleTypes.some(type => !!type.isEntity);
|
|
209
121
|
}
|
|
210
122
|
|
|
211
|
-
static
|
|
212
|
-
return !!fieldTypeInfo && (this.
|
|
123
|
+
static _isNodeRequestFieldPath(fieldTypeInfo) {
|
|
124
|
+
return !!fieldTypeInfo && (this._isNodeEntity(fieldTypeInfo) || fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives);
|
|
213
125
|
}
|
|
214
126
|
|
|
215
127
|
static _isValid(cacheability) {
|
|
@@ -217,6 +129,14 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
217
129
|
return !noCache && cacheability.checkTTL();
|
|
218
130
|
}
|
|
219
131
|
|
|
132
|
+
static _mergeResponseCacheMetadata(cacheMetadata, partialQueryResponse) {
|
|
133
|
+
if (!partialQueryResponse) {
|
|
134
|
+
return cacheMetadata;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return new Map([...partialQueryResponse.cacheMetadata, ...cacheMetadata]);
|
|
138
|
+
}
|
|
139
|
+
|
|
220
140
|
static _setCachedData(requestData, {
|
|
221
141
|
data
|
|
222
142
|
}, propNameOrIndex) {
|
|
@@ -235,18 +155,21 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
235
155
|
}, {
|
|
236
156
|
propNameOrIndex,
|
|
237
157
|
requestFieldPath
|
|
238
|
-
},
|
|
158
|
+
}, typeNamesAndKind, _options, {
|
|
239
159
|
operation
|
|
240
160
|
}) {
|
|
241
161
|
CacheManager._setCacheMetadata(cacheMetadata, cachedFieldData.cacheability, requestFieldPath, operation);
|
|
242
162
|
|
|
243
|
-
CacheManager._setFieldPathChecklist(fieldPathChecklist, cachedFieldData, requestFieldPath,
|
|
163
|
+
CacheManager._setFieldPathChecklist(fieldPathChecklist, cachedFieldData, requestFieldPath, typeNamesAndKind);
|
|
244
164
|
|
|
245
165
|
CacheManager._setCachedData(data, cachedFieldData, propNameOrIndex);
|
|
246
166
|
}
|
|
247
167
|
|
|
248
168
|
static _setCacheMetadata(cacheMetadata, cacheability, requestFieldPath, operation) {
|
|
249
|
-
if (!cacheability)
|
|
169
|
+
if (!cacheability) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
250
173
|
cacheMetadata.set(requestFieldPath, cacheability);
|
|
251
174
|
const operationCacheability = cacheMetadata.get(operation);
|
|
252
175
|
|
|
@@ -259,23 +182,39 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
259
182
|
data
|
|
260
183
|
}, requestFieldPath, {
|
|
261
184
|
dataTypeName,
|
|
262
|
-
fieldTypeName
|
|
185
|
+
fieldTypeName,
|
|
186
|
+
fragmentKind,
|
|
187
|
+
fragmentName
|
|
263
188
|
}) {
|
|
264
|
-
if ((0, _isUndefined2.default)(fieldTypeName)) {
|
|
265
|
-
if (fieldPathChecklist.has(requestFieldPath))
|
|
189
|
+
if ((0, _isUndefined2.default)(fieldTypeName) || fragmentKind === _helpers.FRAGMENT_SPREAD) {
|
|
190
|
+
if (fieldPathChecklist.has(requestFieldPath)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
266
194
|
fieldPathChecklist.set(requestFieldPath, [{
|
|
195
|
+
fragmentKind,
|
|
196
|
+
fragmentName,
|
|
267
197
|
hasData: !(0, _isUndefined2.default)(data)
|
|
268
198
|
}]);
|
|
269
199
|
return;
|
|
270
200
|
}
|
|
271
201
|
|
|
272
|
-
if (dataTypeName !== fieldTypeName)
|
|
202
|
+
if (dataTypeName !== fieldTypeName) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
273
206
|
const entry = fieldPathChecklist.get(requestFieldPath);
|
|
274
207
|
const checklistValues = entry ? entry : [];
|
|
208
|
+
|
|
275
209
|
if (checklistValues.some(({
|
|
276
210
|
typeName
|
|
277
|
-
}) => typeName === dataTypeName))
|
|
211
|
+
}) => typeName === dataTypeName)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
278
215
|
fieldPathChecklist.set(requestFieldPath, [...checklistValues, {
|
|
216
|
+
fragmentKind,
|
|
217
|
+
fragmentName,
|
|
279
218
|
hasData: !(0, _isUndefined2.default)(data),
|
|
280
219
|
typeName: dataTypeName
|
|
281
220
|
}]);
|
|
@@ -316,23 +255,33 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
316
255
|
return Promise.reject(new TypeError("@graphql-box/cache-manager expected an AST."));
|
|
317
256
|
}
|
|
318
257
|
|
|
319
|
-
const
|
|
258
|
+
const cacheManagerContext = { ...context,
|
|
259
|
+
fragmentDefinitions: (0, _helpers.getFragmentDefinitions)(ast),
|
|
260
|
+
typeIDKey: this._typeIDKey
|
|
261
|
+
};
|
|
262
|
+
const cachedResponseData = await this._retrieveCachedResponseData(requestData, options, cacheManagerContext);
|
|
320
263
|
const {
|
|
321
264
|
cacheMetadata,
|
|
322
265
|
data,
|
|
323
266
|
fieldCount
|
|
324
267
|
} = cachedResponseData;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
268
|
+
|
|
269
|
+
if (fieldCount.missing === fieldCount.total) {
|
|
270
|
+
return {
|
|
271
|
+
updated: requestData
|
|
272
|
+
};
|
|
273
|
+
}
|
|
328
274
|
|
|
329
275
|
if (!fieldCount.missing) {
|
|
330
276
|
const dataCaching = this._setQueryResponseCacheEntry(hash, {
|
|
331
277
|
cacheMetadata,
|
|
332
278
|
data
|
|
333
|
-
}, options,
|
|
279
|
+
}, options, cacheManagerContext);
|
|
280
|
+
|
|
281
|
+
if (options.awaitDataCaching) {
|
|
282
|
+
await dataCaching;
|
|
283
|
+
}
|
|
334
284
|
|
|
335
|
-
if (options.awaitDataCaching) await dataCaching;
|
|
336
285
|
return {
|
|
337
286
|
response: {
|
|
338
287
|
cacheMetadata,
|
|
@@ -344,14 +293,19 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
344
293
|
this._setPartialQueryResponse(hash, {
|
|
345
294
|
cacheMetadata,
|
|
346
295
|
data
|
|
347
|
-
}, options,
|
|
296
|
+
}, options, cacheManagerContext);
|
|
348
297
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
298
|
+
const filteredAST = (0, _filterQuery.default)(requestData, cachedResponseData, cacheManagerContext);
|
|
299
|
+
const {
|
|
300
|
+
fragmentDefinitions,
|
|
301
|
+
typeIDKey,
|
|
302
|
+
...rest
|
|
303
|
+
} = cacheManagerContext;
|
|
304
|
+
(0, _assign2.default)(context, rest);
|
|
305
|
+
const request = (0, _graphql.print)(filteredAST);
|
|
352
306
|
return {
|
|
353
307
|
updated: {
|
|
354
|
-
ast,
|
|
308
|
+
ast: filteredAST,
|
|
355
309
|
hash: (0, _helpers.hashRequest)(request),
|
|
356
310
|
request
|
|
357
311
|
}
|
|
@@ -364,7 +318,11 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
364
318
|
|
|
365
319
|
async checkQueryResponseCacheEntry(hash, options, context) {
|
|
366
320
|
const result = await this._checkCacheEntry(_core.QUERY_RESPONSES, hash, options, context);
|
|
367
|
-
|
|
321
|
+
|
|
322
|
+
if (!result) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
|
|
368
326
|
const {
|
|
369
327
|
cacheMetadata,
|
|
370
328
|
data
|
|
@@ -380,101 +338,163 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
380
338
|
}
|
|
381
339
|
|
|
382
340
|
async resolveQuery(requestData, updatedRequestData, rawResponseData, options, context) {
|
|
341
|
+
const cacheManagerContext = { ...context,
|
|
342
|
+
fragmentDefinitions: (0, _helpers.getFragmentDefinitions)(updatedRequestData.ast),
|
|
343
|
+
typeIDKey: this._typeIDKey
|
|
344
|
+
};
|
|
383
345
|
const dataCaching = [];
|
|
384
346
|
const {
|
|
385
347
|
cacheMetadata,
|
|
386
|
-
data
|
|
387
|
-
|
|
348
|
+
data,
|
|
349
|
+
hasNext,
|
|
350
|
+
path
|
|
351
|
+
} = await this._resolveRequest(updatedRequestData, rawResponseData, options, cacheManagerContext);
|
|
388
352
|
let partialQueryResponse;
|
|
389
353
|
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
354
|
+
if (cacheManagerContext.queryFiltered) {
|
|
355
|
+
if (!(rawResponseData.hasNext || rawResponseData.path)) {
|
|
356
|
+
dataCaching.push(this._setQueryResponseCacheEntry(updatedRequestData.hash, {
|
|
357
|
+
cacheMetadata,
|
|
358
|
+
data
|
|
359
|
+
}, options, cacheManagerContext));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (!rawResponseData.path) {
|
|
363
|
+
partialQueryResponse = this._getPartialQueryResponse(requestData.hash);
|
|
364
|
+
}
|
|
396
365
|
}
|
|
397
366
|
|
|
398
|
-
const responseCacheMetadata = CacheManager.
|
|
367
|
+
const responseCacheMetadata = CacheManager._mergeResponseCacheMetadata(cacheMetadata, partialQueryResponse);
|
|
399
368
|
|
|
400
|
-
const responseData = this.
|
|
369
|
+
const responseData = this._mergeResponseData(data, partialQueryResponse);
|
|
370
|
+
|
|
371
|
+
if (!(rawResponseData.hasNext || rawResponseData.path)) {
|
|
372
|
+
dataCaching.push(this._setQueryResponseCacheEntry(requestData.hash, {
|
|
373
|
+
cacheMetadata: responseCacheMetadata,
|
|
374
|
+
data: responseData
|
|
375
|
+
}, options, cacheManagerContext));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (options.awaitDataCaching) {
|
|
379
|
+
await Promise.all(dataCaching);
|
|
380
|
+
}
|
|
401
381
|
|
|
402
|
-
dataCaching.push(this._setQueryResponseCacheEntry(requestData.hash, {
|
|
403
|
-
cacheMetadata: responseCacheMetadata,
|
|
404
|
-
data: responseData
|
|
405
|
-
}, options, context));
|
|
406
|
-
if (options.awaitDataCaching) await Promise.all(dataCaching);
|
|
407
382
|
return {
|
|
408
383
|
cacheMetadata: responseCacheMetadata,
|
|
409
|
-
data: responseData
|
|
384
|
+
data: responseData,
|
|
385
|
+
hasNext,
|
|
386
|
+
path
|
|
410
387
|
};
|
|
411
388
|
}
|
|
412
389
|
|
|
413
390
|
async resolveRequest(requestData, rawResponseData, options, context) {
|
|
414
|
-
|
|
391
|
+
const cacheManagerContext = { ...context,
|
|
392
|
+
fragmentDefinitions: (0, _helpers.getFragmentDefinitions)(requestData.ast),
|
|
393
|
+
typeIDKey: this._typeIDKey
|
|
394
|
+
};
|
|
395
|
+
return this._resolveRequest(requestData, rawResponseData, options, cacheManagerContext);
|
|
415
396
|
}
|
|
416
397
|
|
|
417
|
-
async
|
|
418
|
-
if ((0, _helpers.hasChildFields)(
|
|
419
|
-
await this.
|
|
398
|
+
async _analyzeFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
399
|
+
if ((0, _helpers.hasChildFields)(fieldNode)) {
|
|
400
|
+
await this._analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
|
|
420
401
|
} else {
|
|
421
|
-
await
|
|
402
|
+
await this._analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
|
|
422
403
|
}
|
|
423
404
|
}
|
|
424
405
|
|
|
425
|
-
async
|
|
426
|
-
const keysAndPaths =
|
|
427
|
-
|
|
406
|
+
async _analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
407
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(fieldNode, cachedAncestorFieldData, context);
|
|
428
408
|
const {
|
|
429
409
|
hashedRequestFieldCacheKey,
|
|
430
410
|
propNameOrIndex,
|
|
431
|
-
requestFieldCacheKey,
|
|
432
411
|
requestFieldPath
|
|
433
412
|
} = keysAndPaths;
|
|
434
413
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
435
414
|
const {
|
|
436
|
-
|
|
437
|
-
|
|
415
|
+
entityData,
|
|
416
|
+
fragmentKind,
|
|
417
|
+
fragmentName,
|
|
418
|
+
requestFieldPathData,
|
|
438
419
|
typeName
|
|
439
420
|
} = cachedAncestorFieldData;
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
421
|
+
const typeNamesAndKind = {
|
|
422
|
+
dataTypeName: (entityData === null || entityData === void 0 ? void 0 : entityData.__typename) || (requestFieldPathData === null || requestFieldPathData === void 0 ? void 0 : requestFieldPathData.__typename),
|
|
423
|
+
fieldTypeName: typeName,
|
|
424
|
+
fragmentKind,
|
|
425
|
+
fragmentName
|
|
443
426
|
};
|
|
444
427
|
|
|
445
|
-
if (CacheManager.
|
|
446
|
-
|
|
447
|
-
|
|
428
|
+
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
429
|
+
const {
|
|
430
|
+
cacheability,
|
|
431
|
+
entry
|
|
432
|
+
} = await this._retrieveCachedRequestFieldPathData(hashedRequestFieldCacheKey, options, context);
|
|
448
433
|
|
|
449
|
-
|
|
450
|
-
|
|
434
|
+
CacheManager._setCachedResponseData({
|
|
435
|
+
cacheability,
|
|
436
|
+
data: entry
|
|
437
|
+
}, cachedResponseData, keysAndPaths, typeNamesAndKind, options, context);
|
|
438
|
+
} else {
|
|
439
|
+
const cachedFieldData = CacheManager._getFieldDataFromAncestor(entityData, propNameOrIndex) || CacheManager._getFieldDataFromAncestor(requestFieldPathData, propNameOrIndex);
|
|
440
|
+
|
|
441
|
+
CacheManager._setFieldPathChecklist(cachedResponseData.fieldPathChecklist, {
|
|
442
|
+
data: cachedFieldData
|
|
443
|
+
}, requestFieldPath, typeNamesAndKind);
|
|
444
|
+
|
|
445
|
+
CacheManager._setCachedData(cachedResponseData.data, {
|
|
446
|
+
data: cachedFieldData
|
|
447
|
+
}, propNameOrIndex);
|
|
451
448
|
}
|
|
449
|
+
}
|
|
452
450
|
|
|
451
|
+
async _analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
452
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(fieldNode, cachedAncestorFieldData, context);
|
|
453
|
+
const {
|
|
454
|
+
propNameOrIndex,
|
|
455
|
+
requestFieldCacheKey,
|
|
456
|
+
requestFieldPath
|
|
457
|
+
} = keysAndPaths;
|
|
458
|
+
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
453
459
|
const {
|
|
454
460
|
cacheability,
|
|
455
|
-
|
|
461
|
+
data,
|
|
462
|
+
entityData,
|
|
456
463
|
requestFieldPathData
|
|
457
|
-
} =
|
|
458
|
-
const
|
|
464
|
+
} = await this._retrieveCachedParentNodeData(cachedAncestorFieldData, keysAndPaths, fieldTypeInfo, options, context);
|
|
465
|
+
const {
|
|
466
|
+
fragmentKind,
|
|
467
|
+
fragmentName,
|
|
468
|
+
typeName
|
|
469
|
+
} = cachedAncestorFieldData;
|
|
459
470
|
|
|
460
471
|
CacheManager._setCachedResponseData({
|
|
461
472
|
cacheability,
|
|
462
473
|
data
|
|
463
474
|
}, cachedResponseData, keysAndPaths, {
|
|
464
475
|
dataTypeName: (0, _get2.default)(data, _core.TYPE_NAME_KEY),
|
|
465
|
-
fieldTypeName: typeName
|
|
476
|
+
fieldTypeName: typeName,
|
|
477
|
+
fragmentKind,
|
|
478
|
+
fragmentName
|
|
466
479
|
}, options, context);
|
|
467
480
|
|
|
468
|
-
if (!(0, _isObjectLike2.default)(data))
|
|
481
|
+
if (!(0, _isObjectLike2.default)(data)) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
469
485
|
const objectLikeData = data;
|
|
470
486
|
const promises = [];
|
|
471
|
-
(0, _helpers.iterateChildFields)(
|
|
472
|
-
promises.push(this.
|
|
487
|
+
(0, _helpers.iterateChildFields)(fieldNode, objectLikeData, context.fragmentDefinitions, (childField, childTypeName, childFragmentKind, childFragmentName, childIndex) => {
|
|
488
|
+
promises.push(this._analyzeFieldNode(childField, {
|
|
489
|
+
cacheability,
|
|
490
|
+
entityData,
|
|
491
|
+
fragmentKind: childFragmentKind,
|
|
492
|
+
fragmentName: childFragmentName,
|
|
473
493
|
index: childIndex,
|
|
474
494
|
requestFieldCacheKey,
|
|
475
495
|
requestFieldPath,
|
|
476
|
-
|
|
477
|
-
|
|
496
|
+
requestFieldPathData,
|
|
497
|
+
typeName: childTypeName
|
|
478
498
|
}, { ...cachedResponseData,
|
|
479
499
|
data: cachedResponseData.data[propNameOrIndex]
|
|
480
500
|
}, options, context));
|
|
@@ -495,7 +515,11 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
495
515
|
|
|
496
516
|
const queryNode = (0, _helpers.getOperationDefinitions)(ast, context.operation)[0];
|
|
497
517
|
const fieldsAndTypeNames = (0, _helpers.getChildFields)(queryNode);
|
|
498
|
-
|
|
518
|
+
|
|
519
|
+
if (!fieldsAndTypeNames) {
|
|
520
|
+
return cacheMetadata;
|
|
521
|
+
}
|
|
522
|
+
|
|
499
523
|
fieldsAndTypeNames.forEach(({
|
|
500
524
|
fieldNode
|
|
501
525
|
}) => this._setFieldCacheability(fieldNode, {
|
|
@@ -510,9 +534,17 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
510
534
|
async _checkCacheEntry(cacheType, hash, options, context) {
|
|
511
535
|
try {
|
|
512
536
|
const cacheability = await this._hasCacheEntry(cacheType, hash);
|
|
513
|
-
|
|
537
|
+
|
|
538
|
+
if (!cacheability || !CacheManager._isValid(cacheability)) {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
|
|
514
542
|
const entry = await this._getCacheEntry(cacheType, hash, options, context);
|
|
515
|
-
|
|
543
|
+
|
|
544
|
+
if ((0, _isUndefined2.default)(entry)) {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
|
|
516
548
|
return {
|
|
517
549
|
cacheability,
|
|
518
550
|
entry
|
|
@@ -543,148 +575,6 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
543
575
|
return cacheMetadata;
|
|
544
576
|
}
|
|
545
577
|
|
|
546
|
-
_filterField(field, fieldPathChecklist, ancestorRequestFieldPath, context) {
|
|
547
|
-
const fieldsAndTypeNames = (0, _helpers.getChildFields)(field);
|
|
548
|
-
if (!fieldsAndTypeNames) return false;
|
|
549
|
-
|
|
550
|
-
for (let i = fieldsAndTypeNames.length - 1; i >= 0; i -= 1) {
|
|
551
|
-
const {
|
|
552
|
-
fieldNode: childField,
|
|
553
|
-
typeName: childTypeName
|
|
554
|
-
} = fieldsAndTypeNames[i];
|
|
555
|
-
const childFieldName = (0, _helpers.getName)(childField);
|
|
556
|
-
if (childFieldName === this._typeIDKey || childFieldName === _core.TYPE_NAME_KEY) continue;
|
|
557
|
-
|
|
558
|
-
const {
|
|
559
|
-
requestFieldPath
|
|
560
|
-
} = CacheManager._getFieldKeysAndPaths(childField, {
|
|
561
|
-
requestFieldPath: ancestorRequestFieldPath
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
const {
|
|
565
|
-
hasData,
|
|
566
|
-
typeUnused
|
|
567
|
-
} = CacheManager._checkFieldPathChecklist(fieldPathChecklist.get(requestFieldPath), childTypeName);
|
|
568
|
-
|
|
569
|
-
if (hasData || typeUnused) {
|
|
570
|
-
if (!(0, _helpers.hasChildFields)(childField)) {
|
|
571
|
-
(0, _helpers.deleteChildFields)(field, childField);
|
|
572
|
-
} else if (this._filterField(childField, fieldPathChecklist, requestFieldPath, context)) {
|
|
573
|
-
(0, _helpers.deleteChildFields)(field, childField);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
this._filterInlineFragments(field);
|
|
579
|
-
|
|
580
|
-
this._filterIDsAndTypeNames(field);
|
|
581
|
-
|
|
582
|
-
return !(0, _helpers.hasChildFields)(field);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
_filterIDsAndTypeNames(field) {
|
|
586
|
-
const fieldsAndTypeNames = (0, _helpers.getChildFields)(field);
|
|
587
|
-
if (!fieldsAndTypeNames || fieldsAndTypeNames.length > 3) return false;
|
|
588
|
-
const fieldNames = fieldsAndTypeNames.map(({
|
|
589
|
-
fieldNode
|
|
590
|
-
}) => (0, _helpers.getName)(fieldNode));
|
|
591
|
-
|
|
592
|
-
if (fieldNames.length === 2 && fieldNames.every(name => name === this._typeIDKey || name === _core.TYPE_NAME_KEY)) {
|
|
593
|
-
(0, _helpers.deleteChildFields)(field, fieldsAndTypeNames.map(({
|
|
594
|
-
fieldNode
|
|
595
|
-
}) => fieldNode));
|
|
596
|
-
return true;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
if (fieldNames.length === 1 && fieldNames[0] === this._typeIDKey || fieldNames[0] === _core.TYPE_NAME_KEY) {
|
|
600
|
-
const {
|
|
601
|
-
fieldNode
|
|
602
|
-
} = fieldsAndTypeNames[0];
|
|
603
|
-
(0, _helpers.deleteChildFields)(field, fieldNode);
|
|
604
|
-
return true;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
return false;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
_filterInlineFragments(field) {
|
|
611
|
-
const inlineFragments = (0, _helpers.getInlineFragments)(field);
|
|
612
|
-
let filtered = false;
|
|
613
|
-
inlineFragments.forEach(fragment => {
|
|
614
|
-
const fieldsAndTypeNames = (0, _helpers.getChildFields)(fragment);
|
|
615
|
-
|
|
616
|
-
if (!fieldsAndTypeNames || !fieldsAndTypeNames.length) {
|
|
617
|
-
(0, _helpers.deleteInlineFragments)(field, fragment);
|
|
618
|
-
filtered = true;
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (fieldsAndTypeNames.length === 1) {
|
|
623
|
-
const {
|
|
624
|
-
fieldNode
|
|
625
|
-
} = fieldsAndTypeNames[0];
|
|
626
|
-
|
|
627
|
-
if ((0, _helpers.getName)(fieldNode) === this._typeIDKey) {
|
|
628
|
-
(0, _helpers.deleteInlineFragments)(field, fragment);
|
|
629
|
-
filtered = true;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
return filtered;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
_filterQuery({
|
|
637
|
-
ast
|
|
638
|
-
}, {
|
|
639
|
-
fieldPathChecklist
|
|
640
|
-
}, context) {
|
|
641
|
-
const queryNode = (0, _helpers.getOperationDefinitions)(ast, context.operation)[0];
|
|
642
|
-
const fieldsAndTypeNames = (0, _helpers.getChildFields)(queryNode);
|
|
643
|
-
if (!fieldsAndTypeNames) return;
|
|
644
|
-
|
|
645
|
-
for (let i = fieldsAndTypeNames.length - 1; i >= 0; i -= 1) {
|
|
646
|
-
const {
|
|
647
|
-
fieldNode
|
|
648
|
-
} = fieldsAndTypeNames[i];
|
|
649
|
-
|
|
650
|
-
const {
|
|
651
|
-
requestFieldPath
|
|
652
|
-
} = CacheManager._getFieldKeysAndPaths(fieldNode, {
|
|
653
|
-
requestFieldPath: context.operation
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
if (this._filterField(fieldNode, fieldPathChecklist, requestFieldPath, context)) {
|
|
657
|
-
(0, _helpers.deleteChildFields)(queryNode, fieldNode);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
context.queryFiltered = true;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
async _getCachedResponseData({
|
|
665
|
-
ast
|
|
666
|
-
}, options, context) {
|
|
667
|
-
const cachedResponseData = {
|
|
668
|
-
cacheMetadata: new Map(),
|
|
669
|
-
data: {},
|
|
670
|
-
fieldCount: {
|
|
671
|
-
missing: 0,
|
|
672
|
-
total: 0
|
|
673
|
-
},
|
|
674
|
-
fieldPathChecklist: new Map()
|
|
675
|
-
};
|
|
676
|
-
const queryNode = (0, _helpers.getOperationDefinitions)(ast, context.operation)[0];
|
|
677
|
-
const fieldsAndTypeNames = (0, _helpers.getChildFields)(queryNode);
|
|
678
|
-
if (!fieldsAndTypeNames) return cachedResponseData;
|
|
679
|
-
await Promise.all(fieldsAndTypeNames.map(({
|
|
680
|
-
fieldNode
|
|
681
|
-
}) => this._analyzeField(fieldNode, {
|
|
682
|
-
requestFieldPath: context.operation
|
|
683
|
-
}, cachedResponseData, options, context)));
|
|
684
|
-
cachedResponseData.fieldCount = CacheManager._countFieldPathChecklist(cachedResponseData.fieldPathChecklist);
|
|
685
|
-
return cachedResponseData;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
578
|
async _getCacheEntry(cacheType, hash, _options, _context) {
|
|
689
579
|
try {
|
|
690
580
|
return await this._cache.get(`${cacheType}::${hash}`);
|
|
@@ -701,11 +591,6 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
701
591
|
return partialQueryResponse;
|
|
702
592
|
}
|
|
703
593
|
|
|
704
|
-
_getResponseData(responseData, partialQueryResponse) {
|
|
705
|
-
if (!partialQueryResponse) return responseData;
|
|
706
|
-
return this._mergeObjects(partialQueryResponse.data, responseData);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
594
|
async _hasCacheEntry(cacheType, hash) {
|
|
710
595
|
try {
|
|
711
596
|
return await this._cache.has(`${cacheType}::${hash}`);
|
|
@@ -718,9 +603,18 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
718
603
|
isEntity,
|
|
719
604
|
possibleTypes
|
|
720
605
|
}) {
|
|
721
|
-
if (!(0, _get2.default)(fieldData, this._typeIDKey, null))
|
|
722
|
-
|
|
723
|
-
|
|
606
|
+
if (!(0, _get2.default)(fieldData, this._typeIDKey, null)) {
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (isEntity) {
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (!possibleTypes.length) {
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
|
|
724
618
|
return possibleTypes.some(type => type.typeName === fieldData.__typename);
|
|
725
619
|
}
|
|
726
620
|
|
|
@@ -730,126 +624,89 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
730
624
|
});
|
|
731
625
|
}
|
|
732
626
|
|
|
733
|
-
|
|
627
|
+
_mergeResponseData(responseData, partialQueryResponse) {
|
|
628
|
+
if (!partialQueryResponse) {
|
|
629
|
+
return responseData;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
return this._mergeObjects(partialQueryResponse.data, responseData);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
async _parseEntityAndRequestFieldPathCacheEntryData(field, ancestorKeysAndPaths, {
|
|
734
636
|
cacheMetadata,
|
|
735
|
-
|
|
637
|
+
entityData,
|
|
736
638
|
requestFieldPathData
|
|
737
639
|
}, options, context) {
|
|
738
|
-
const keysAndPaths =
|
|
739
|
-
|
|
640
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(field, ancestorKeysAndPaths, context);
|
|
740
641
|
const {
|
|
741
642
|
requestFieldCacheKey,
|
|
742
643
|
requestFieldPath,
|
|
743
644
|
responseDataPath
|
|
744
645
|
} = keysAndPaths;
|
|
745
|
-
const fieldData = (0, _get2.default)(requestFieldPathData, responseDataPath
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
646
|
+
const fieldData = (0, _get2.default)(requestFieldPathData, responseDataPath);
|
|
647
|
+
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
648
|
+
|
|
649
|
+
if (!(0, _isObjectLike2.default)(fieldData) && !(fieldTypeInfo !== null && fieldTypeInfo !== void 0 && fieldTypeInfo.hasDirectives)) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if ((0, _isObjectLike2.default)(fieldData)) {
|
|
654
|
+
const promises = [];
|
|
655
|
+
(0, _helpers.iterateChildFields)(field, fieldData, context.fragmentDefinitions, (childField, _typeName, _fragmentKind, _fragmentName, childIndex) => {
|
|
656
|
+
promises.push(this._parseEntityAndRequestFieldPathCacheEntryData(childField, {
|
|
657
|
+
index: childIndex,
|
|
658
|
+
requestFieldCacheKey,
|
|
659
|
+
requestFieldPath,
|
|
660
|
+
responseDataPath
|
|
661
|
+
}, {
|
|
662
|
+
cacheMetadata,
|
|
663
|
+
entityData,
|
|
664
|
+
requestFieldPathData
|
|
665
|
+
}, options, context));
|
|
666
|
+
});
|
|
667
|
+
await Promise.all(promises);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
await this._setEntityAndRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
763
671
|
cacheMetadata,
|
|
764
|
-
|
|
672
|
+
entityData,
|
|
765
673
|
requestFieldPathData
|
|
766
674
|
}, options, context);
|
|
767
675
|
}
|
|
768
676
|
|
|
769
677
|
async _resolveRequest(requestData, rawResponseData, options, context) {
|
|
678
|
+
const normalizedResponseData = rawResponseData.path ? (0, _normalizeResponseData.default)(rawResponseData) : rawResponseData;
|
|
770
679
|
const dataCaching = [];
|
|
771
680
|
|
|
772
|
-
const cacheMetadata = this._buildCacheMetadata(requestData,
|
|
681
|
+
const cacheMetadata = this._buildCacheMetadata(requestData, normalizedResponseData, options, context);
|
|
773
682
|
|
|
774
683
|
const {
|
|
775
|
-
data
|
|
776
|
-
|
|
777
|
-
|
|
684
|
+
data,
|
|
685
|
+
hasNext,
|
|
686
|
+
path
|
|
687
|
+
} = normalizedResponseData;
|
|
688
|
+
dataCaching.push(this._setEntityAndRequestFieldPathCacheEntries(requestData, {
|
|
778
689
|
cacheMetadata,
|
|
779
|
-
|
|
690
|
+
entityData: (0, _cloneDeep2.default)(data),
|
|
780
691
|
requestFieldPathData: (0, _cloneDeep2.default)(data)
|
|
781
692
|
}, options, context));
|
|
782
|
-
if (options.awaitDataCaching) await Promise.all(dataCaching);
|
|
783
|
-
return {
|
|
784
|
-
cacheMetadata,
|
|
785
|
-
data
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
async _setCacheEntry(cacheType, hash, value, cachemapOptions, _options, _context) {
|
|
790
|
-
try {
|
|
791
|
-
await this._cache.set(`${cacheType}::${hash}`, (0, _cloneDeep2.default)(value), cachemapOptions);
|
|
792
|
-
} catch (error) {}
|
|
793
|
-
}
|
|
794
693
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
const fieldsAndTypeNames = (0, _helpers.getChildFields)(operationNode);
|
|
798
|
-
if (!fieldsAndTypeNames) return;
|
|
799
|
-
await Promise.all(fieldsAndTypeNames.map(({
|
|
800
|
-
fieldNode
|
|
801
|
-
}) => {
|
|
802
|
-
return this._parseFieldDataEntityAndRequestFieldPathCacheEntryData(fieldNode, {
|
|
803
|
-
requestFieldPath: context.operation
|
|
804
|
-
}, responseData, options, context);
|
|
805
|
-
}));
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
async _setDataEntityCacheEntry({
|
|
809
|
-
responseDataPath
|
|
810
|
-
}, {
|
|
811
|
-
cacheability,
|
|
812
|
-
data,
|
|
813
|
-
fieldTypeInfo
|
|
814
|
-
}, options, context) {
|
|
815
|
-
const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
|
|
816
|
-
let fieldData = (0, _get2.default)(data, responseDataPath, null);
|
|
817
|
-
|
|
818
|
-
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
819
|
-
|
|
820
|
-
if (!isEntity && hasArgsOrDirectives) {
|
|
821
|
-
(0, _unset2.default)(data, responseDataPath);
|
|
694
|
+
if (options.awaitDataCaching) {
|
|
695
|
+
await Promise.all(dataCaching);
|
|
822
696
|
}
|
|
823
697
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
fieldData = this._mergeObjects(result.entry, fieldData);
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
await this._setCacheEntry(_core.DATA_ENTITIES, entityDataKey, fieldData, {
|
|
834
|
-
cacheHeaders: {
|
|
835
|
-
cacheControl: cacheability.printCacheControl()
|
|
836
|
-
},
|
|
837
|
-
tag: options.tag
|
|
838
|
-
}, options, context);
|
|
839
|
-
(0, _set2.default)(data, responseDataPath, {
|
|
840
|
-
__cacheKey: `${_core.DATA_ENTITIES}::${entityDataKey}`
|
|
841
|
-
});
|
|
842
|
-
}
|
|
698
|
+
return {
|
|
699
|
+
cacheMetadata,
|
|
700
|
+
data,
|
|
701
|
+
hasNext,
|
|
702
|
+
path
|
|
703
|
+
};
|
|
843
704
|
}
|
|
844
705
|
|
|
845
|
-
async
|
|
706
|
+
async _retrieveCachedEntityData(validTypeIDValue, {
|
|
846
707
|
possibleTypes,
|
|
847
|
-
typeIDValue,
|
|
848
708
|
typeName
|
|
849
709
|
}, options, context) {
|
|
850
|
-
const requestFieldPathDataIDValue = (0, _isPlainObject2.default)(cachedFieldData.requestFieldPathData) ? cachedFieldData.requestFieldPathData[this._typeIDKey] : undefined;
|
|
851
|
-
const validTypeIDValue = typeIDValue || requestFieldPathDataIDValue;
|
|
852
|
-
if (!validTypeIDValue) return;
|
|
853
710
|
const typeNames = [...possibleTypes.map(type => type.typeName), typeName];
|
|
854
711
|
const checkResults = await Promise.all(typeNames.map(name => this._checkCacheEntry(_core.DATA_ENTITIES, `${name}::${validTypeIDValue}`, options, context)));
|
|
855
712
|
const validResults = checkResults.filter(result => !!result);
|
|
@@ -871,76 +728,228 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
871
728
|
};
|
|
872
729
|
}
|
|
873
730
|
|
|
874
|
-
|
|
731
|
+
return validResult || {};
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
async _retrieveCachedParentNodeData({
|
|
735
|
+
entityData: ancestorEntityData,
|
|
736
|
+
requestFieldPathData: ancestorRequestFieldPathData
|
|
737
|
+
}, {
|
|
738
|
+
hashedRequestFieldCacheKey,
|
|
739
|
+
propNameOrIndex
|
|
740
|
+
}, fieldTypeInfo, options, context) {
|
|
741
|
+
var _entityData;
|
|
742
|
+
|
|
743
|
+
let entityData = CacheManager._getFieldDataFromAncestor(ancestorEntityData, propNameOrIndex);
|
|
744
|
+
|
|
745
|
+
let requestFieldPathData = CacheManager._getFieldDataFromAncestor(ancestorRequestFieldPathData, propNameOrIndex);
|
|
746
|
+
|
|
747
|
+
let cacheability;
|
|
748
|
+
|
|
749
|
+
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
875
750
|
const {
|
|
876
|
-
cacheability,
|
|
751
|
+
cacheability: entryCacheability,
|
|
877
752
|
entry
|
|
878
|
-
} =
|
|
879
|
-
|
|
880
|
-
if (entry)
|
|
753
|
+
} = await this._retrieveCachedRequestFieldPathData(hashedRequestFieldCacheKey, options, context);
|
|
754
|
+
|
|
755
|
+
if (entry) {
|
|
756
|
+
requestFieldPathData = this._mergeObjects(requestFieldPathData, entry);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
if (entryCacheability) {
|
|
760
|
+
cacheability = entryCacheability;
|
|
761
|
+
}
|
|
881
762
|
}
|
|
763
|
+
|
|
764
|
+
const validTypeIDValue = (0, _validTypeIDValue.getValidTypeIDValue)(requestFieldPathData, fieldTypeInfo, this._typeIDKey);
|
|
765
|
+
|
|
766
|
+
if (CacheManager._isNodeEntity(fieldTypeInfo) && validTypeIDValue) {
|
|
767
|
+
var _cacheability;
|
|
768
|
+
|
|
769
|
+
const {
|
|
770
|
+
cacheability: entryCacheability,
|
|
771
|
+
entry
|
|
772
|
+
} = await this._retrieveCachedEntityData(validTypeIDValue, fieldTypeInfo, options, context);
|
|
773
|
+
|
|
774
|
+
if (entry) {
|
|
775
|
+
entityData = this._mergeObjects(entityData, entry);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (entryCacheability && (!cacheability || entryCacheability.metadata.ttl > ((_cacheability = cacheability) === null || _cacheability === void 0 ? void 0 : _cacheability.metadata.ttl))) {
|
|
779
|
+
cacheability = entryCacheability;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const data = !(0, _isUndefined2.default)(requestFieldPathData) || !(0, _isUndefined2.default)(entityData) ? this._mergeObjects(requestFieldPathData, entityData) : (_entityData = entityData) !== null && _entityData !== void 0 ? _entityData : requestFieldPathData;
|
|
784
|
+
return {
|
|
785
|
+
cacheability,
|
|
786
|
+
data,
|
|
787
|
+
entityData,
|
|
788
|
+
requestFieldPathData
|
|
789
|
+
};
|
|
882
790
|
}
|
|
883
791
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
792
|
+
async _retrieveCachedRequestFieldPathData(hash, options, context) {
|
|
793
|
+
return this._checkCacheEntry(_core.REQUEST_FIELD_PATHS, hash, options, context) || {};
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
async _retrieveCachedResponseData({
|
|
797
|
+
ast
|
|
887
798
|
}, options, context) {
|
|
888
|
-
const {
|
|
889
|
-
|
|
890
|
-
|
|
799
|
+
const cachedResponseData = {
|
|
800
|
+
cacheMetadata: new Map(),
|
|
801
|
+
data: {},
|
|
802
|
+
fieldCount: {
|
|
803
|
+
missing: 0,
|
|
804
|
+
total: 0
|
|
805
|
+
},
|
|
806
|
+
fieldPathChecklist: new Map()
|
|
807
|
+
};
|
|
808
|
+
const queryNode = (0, _helpers.getOperationDefinitions)(ast, context.operation)[0];
|
|
809
|
+
const fieldsAndTypeNames = (0, _helpers.getChildFields)(queryNode);
|
|
891
810
|
|
|
892
|
-
|
|
811
|
+
if (!fieldsAndTypeNames) {
|
|
812
|
+
return cachedResponseData;
|
|
813
|
+
}
|
|
893
814
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
815
|
+
await Promise.all(fieldsAndTypeNames.map(({
|
|
816
|
+
fieldNode
|
|
817
|
+
}) => this._analyzeFieldNode(fieldNode, {
|
|
818
|
+
requestFieldPath: context.operation
|
|
819
|
+
}, cachedResponseData, options, context)));
|
|
820
|
+
cachedResponseData.fieldCount = CacheManager._countFieldPathChecklist(cachedResponseData.fieldPathChecklist);
|
|
821
|
+
return cachedResponseData;
|
|
822
|
+
}
|
|
901
823
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
824
|
+
async _setCacheEntry(cacheType, hash, value, cachemapOptions, _options, _context) {
|
|
825
|
+
try {
|
|
826
|
+
await this._cache.set(`${cacheType}::${hash}`, (0, _cloneDeep2.default)(value), cachemapOptions);
|
|
827
|
+
} catch (error) {}
|
|
828
|
+
}
|
|
906
829
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
830
|
+
async _setEntityAndRequestFieldPathCacheEntries(requestData, responseData, options, context) {
|
|
831
|
+
const operationNode = (0, _helpers.getOperationDefinitions)(requestData.ast, context.operation)[0];
|
|
832
|
+
const fieldsAndTypeNames = (0, _helpers.getChildFields)(operationNode);
|
|
833
|
+
|
|
834
|
+
if (!fieldsAndTypeNames) {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
await Promise.all(fieldsAndTypeNames.map(({
|
|
839
|
+
fieldNode
|
|
840
|
+
}) => {
|
|
841
|
+
return this._parseEntityAndRequestFieldPathCacheEntryData(fieldNode, {
|
|
842
|
+
requestFieldPath: context.operation
|
|
843
|
+
}, responseData, options, context);
|
|
844
|
+
}));
|
|
917
845
|
}
|
|
918
846
|
|
|
919
|
-
async
|
|
847
|
+
async _setEntityAndRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
920
848
|
cacheMetadata,
|
|
921
|
-
|
|
849
|
+
entityData,
|
|
922
850
|
requestFieldPathData
|
|
923
851
|
}, options, context) {
|
|
924
852
|
const {
|
|
925
|
-
requestFieldPath
|
|
853
|
+
requestFieldPath,
|
|
854
|
+
responseDataPath
|
|
926
855
|
} = keysAndPaths;
|
|
856
|
+
const fieldData = (0, _get2.default)(entityData, responseDataPath);
|
|
927
857
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
928
858
|
const cacheability = cacheMetadata.get(requestFieldPath);
|
|
929
|
-
|
|
859
|
+
|
|
860
|
+
if ((0, _isUndefined2.default)(fieldData) || !fieldTypeInfo || !cacheability) {
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
|
|
930
864
|
const promises = [];
|
|
931
865
|
promises.push(this._setRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
932
866
|
cacheability,
|
|
933
867
|
data: requestFieldPathData,
|
|
934
868
|
fieldTypeInfo
|
|
935
869
|
}, options, context));
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
870
|
+
|
|
871
|
+
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
872
|
+
|
|
873
|
+
if (!isEntity && fieldTypeInfo.hasArguments) {
|
|
874
|
+
(0, _unset2.default)(entityData, responseDataPath);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if (isEntity) {
|
|
878
|
+
promises.push(this._setEntityCacheEntry(keysAndPaths, {
|
|
879
|
+
cacheability,
|
|
880
|
+
data: entityData,
|
|
881
|
+
fieldTypeInfo
|
|
882
|
+
}, options, context));
|
|
883
|
+
}
|
|
884
|
+
|
|
941
885
|
await Promise.all(promises);
|
|
942
886
|
}
|
|
943
887
|
|
|
888
|
+
async _setEntityCacheEntry({
|
|
889
|
+
responseDataPath
|
|
890
|
+
}, {
|
|
891
|
+
cacheability,
|
|
892
|
+
data,
|
|
893
|
+
fieldTypeInfo
|
|
894
|
+
}, options, context) {
|
|
895
|
+
let fieldData = (0, _get2.default)(data, responseDataPath);
|
|
896
|
+
const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
|
|
897
|
+
const entityDataKey = `${fieldTypeName}::${fieldData[this._typeIDKey]}`;
|
|
898
|
+
const result = await this._checkCacheEntry(_core.DATA_ENTITIES, entityDataKey, options, context);
|
|
899
|
+
|
|
900
|
+
if (result) {
|
|
901
|
+
fieldData = this._mergeObjects(result.entry, fieldData);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
await this._setCacheEntry(_core.DATA_ENTITIES, entityDataKey, fieldData, {
|
|
905
|
+
cacheHeaders: {
|
|
906
|
+
cacheControl: cacheability.printCacheControl()
|
|
907
|
+
},
|
|
908
|
+
tag: options.tag
|
|
909
|
+
}, options, context);
|
|
910
|
+
(0, _set2.default)(data, responseDataPath, {
|
|
911
|
+
__cacheKey: `${_core.DATA_ENTITIES}::${entityDataKey}`
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
_setFieldCacheability(field, ancestorKeysAndPaths, {
|
|
916
|
+
cacheMetadata,
|
|
917
|
+
data
|
|
918
|
+
}, options, context) {
|
|
919
|
+
const {
|
|
920
|
+
requestFieldPath: ancestorRequestFieldPath
|
|
921
|
+
} = ancestorKeysAndPaths;
|
|
922
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(field, ancestorKeysAndPaths, context);
|
|
923
|
+
const {
|
|
924
|
+
requestFieldPath,
|
|
925
|
+
responseDataPath
|
|
926
|
+
} = keysAndPaths;
|
|
927
|
+
const fieldData = (0, _get2.default)(data, responseDataPath);
|
|
928
|
+
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
929
|
+
|
|
930
|
+
if (!(0, _isObjectLike2.default)(fieldData) && !(fieldTypeInfo !== null && fieldTypeInfo !== void 0 && fieldTypeInfo.hasDirectives)) {
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
this._setFieldTypeCacheDirective(cacheMetadata, {
|
|
935
|
+
ancestorRequestFieldPath,
|
|
936
|
+
requestFieldPath
|
|
937
|
+
}, context);
|
|
938
|
+
|
|
939
|
+
if ((0, _isObjectLike2.default)(fieldData)) {
|
|
940
|
+
(0, _helpers.iterateChildFields)(field, fieldData, context.fragmentDefinitions, (childField, _typeName, _fragmentKind, _fragmentName, childIndex) => {
|
|
941
|
+
this._setFieldCacheability(childField, {
|
|
942
|
+
index: childIndex,
|
|
943
|
+
requestFieldPath,
|
|
944
|
+
responseDataPath
|
|
945
|
+
}, {
|
|
946
|
+
cacheMetadata,
|
|
947
|
+
data
|
|
948
|
+
}, options, context);
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
944
953
|
_setFieldTypeCacheDirective(cacheMetadata, {
|
|
945
954
|
ancestorRequestFieldPath,
|
|
946
955
|
requestFieldPath
|
|
@@ -948,11 +957,14 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
948
957
|
fieldTypeMap,
|
|
949
958
|
operation
|
|
950
959
|
}) {
|
|
951
|
-
if (cacheMetadata.has(requestFieldPath))
|
|
960
|
+
if (cacheMetadata.has(requestFieldPath)) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
|
|
952
964
|
const fieldTypeInfo = fieldTypeMap.get(requestFieldPath);
|
|
953
965
|
|
|
954
966
|
if (fieldTypeInfo && this._typeCacheDirectives[fieldTypeInfo.typeName]) {
|
|
955
|
-
const cacheability = new
|
|
967
|
+
const cacheability = new _cacheability2.default({
|
|
956
968
|
cacheControl: this._typeCacheDirectives[fieldTypeInfo.typeName]
|
|
957
969
|
});
|
|
958
970
|
|
|
@@ -985,23 +997,31 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
985
997
|
}, options, context);
|
|
986
998
|
}
|
|
987
999
|
|
|
988
|
-
async _setRequestFieldPathCacheEntry(field, {
|
|
989
|
-
hashedRequestFieldCacheKey,
|
|
990
|
-
responseDataPath
|
|
991
|
-
}, {
|
|
1000
|
+
async _setRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
992
1001
|
cacheability,
|
|
993
1002
|
data,
|
|
994
1003
|
fieldTypeInfo
|
|
995
1004
|
}, options, context) {
|
|
996
|
-
const
|
|
997
|
-
|
|
1005
|
+
const {
|
|
1006
|
+
hashedRequestFieldCacheKey,
|
|
1007
|
+
responseDataPath
|
|
1008
|
+
} = keysAndPaths;
|
|
1009
|
+
let fieldData = (0, _get2.default)(data, responseDataPath);
|
|
998
1010
|
|
|
999
1011
|
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
1000
1012
|
|
|
1013
|
+
const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
|
|
1014
|
+
|
|
1001
1015
|
if (context.operation === _core.QUERY && (isEntity || hasArgsOrDirectives)) {
|
|
1016
|
+
var _field$selectionSet;
|
|
1017
|
+
|
|
1018
|
+
if ((0, _isPlainObject2.default)(fieldData) && (_field$selectionSet = field.selectionSet) !== null && _field$selectionSet !== void 0 && _field$selectionSet.selections) {
|
|
1019
|
+
fieldData = (0, _filterOutPropsWithArgsOrDirectives.default)(fieldData, field.selectionSet.selections, keysAndPaths, context);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1002
1022
|
const result = await this._checkCacheEntry(_core.REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, context);
|
|
1003
1023
|
|
|
1004
|
-
if (result) {
|
|
1024
|
+
if (result && (0, _isObjectLike2.default)(fieldData)) {
|
|
1005
1025
|
fieldData = this._mergeObjects(result.entry, fieldData);
|
|
1006
1026
|
}
|
|
1007
1027
|
|
|
@@ -1024,19 +1044,6 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
1024
1044
|
}
|
|
1025
1045
|
}
|
|
1026
1046
|
|
|
1027
|
-
async _setRequestFieldPathData(cachedFieldData, hash, options, context) {
|
|
1028
|
-
const checkResult = await this._checkCacheEntry(_core.REQUEST_FIELD_PATHS, hash, options, context);
|
|
1029
|
-
|
|
1030
|
-
if (checkResult) {
|
|
1031
|
-
const {
|
|
1032
|
-
cacheability,
|
|
1033
|
-
entry
|
|
1034
|
-
} = checkResult;
|
|
1035
|
-
if (cacheability) cachedFieldData.cacheability = cacheability;
|
|
1036
|
-
if (entry) cachedFieldData.requestFieldPathData = entry;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
1047
|
}, ((0, _applyDecoratedDescriptor2.default)(_class.prototype, "_getCacheEntry", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "_getCacheEntry"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_setCacheEntry", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "_setCacheEntry"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_setPartialQueryResponse", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "_setPartialQueryResponse"), _class.prototype)), _class));
|
|
1041
1048
|
exports.CacheManager = CacheManager;
|
|
1042
1049
|
|