@graphql-box/cache-manager 2.1.4 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +23 -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 +468 -472
- 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 +11 -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 +465 -470
- 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 +10 -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 +13 -20
- package/lib/types/main/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__snapshots__/index.test.ts.snap +17449 -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 +9 -0
- package/src/helpers/validTypeIDValue.ts +11 -0
- package/src/index.test.ts +179 -3
- package/src/main/index.ts +506 -499
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,33 @@ 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
111
|
static _getResponseCacheMetadata(cacheMetadata, partialQueryResponse) {
|
|
198
|
-
if (!partialQueryResponse)
|
|
112
|
+
if (!partialQueryResponse) {
|
|
113
|
+
return cacheMetadata;
|
|
114
|
+
}
|
|
115
|
+
|
|
199
116
|
return new Map([...partialQueryResponse.cacheMetadata, ...cacheMetadata]);
|
|
200
117
|
}
|
|
201
118
|
|
|
202
|
-
static
|
|
203
|
-
if (!fieldTypeInfo)
|
|
119
|
+
static _isNodeEntity(fieldTypeInfo) {
|
|
120
|
+
if (!fieldTypeInfo) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
204
124
|
const {
|
|
205
125
|
isEntity,
|
|
206
126
|
possibleTypes
|
|
@@ -208,8 +128,8 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
208
128
|
return isEntity || possibleTypes.some(type => !!type.isEntity);
|
|
209
129
|
}
|
|
210
130
|
|
|
211
|
-
static
|
|
212
|
-
return !!fieldTypeInfo && (this.
|
|
131
|
+
static _isNodeRequestFieldPath(fieldTypeInfo) {
|
|
132
|
+
return !!fieldTypeInfo && (this._isNodeEntity(fieldTypeInfo) || fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives);
|
|
213
133
|
}
|
|
214
134
|
|
|
215
135
|
static _isValid(cacheability) {
|
|
@@ -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,18 +338,23 @@ 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
|
+
} = await this._resolveRequest(updatedRequestData, rawResponseData, options, cacheManagerContext);
|
|
388
351
|
let partialQueryResponse;
|
|
389
352
|
|
|
390
|
-
if (
|
|
353
|
+
if (cacheManagerContext.queryFiltered) {
|
|
391
354
|
dataCaching.push(this._setQueryResponseCacheEntry(updatedRequestData.hash, {
|
|
392
355
|
cacheMetadata,
|
|
393
356
|
data
|
|
394
|
-
}, options,
|
|
357
|
+
}, options, cacheManagerContext));
|
|
395
358
|
partialQueryResponse = this._getPartialQueryResponse(requestData.hash);
|
|
396
359
|
}
|
|
397
360
|
|
|
@@ -402,79 +365,127 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
402
365
|
dataCaching.push(this._setQueryResponseCacheEntry(requestData.hash, {
|
|
403
366
|
cacheMetadata: responseCacheMetadata,
|
|
404
367
|
data: responseData
|
|
405
|
-
}, options,
|
|
406
|
-
|
|
368
|
+
}, options, cacheManagerContext));
|
|
369
|
+
|
|
370
|
+
if (options.awaitDataCaching) {
|
|
371
|
+
await Promise.all(dataCaching);
|
|
372
|
+
}
|
|
373
|
+
|
|
407
374
|
return {
|
|
408
375
|
cacheMetadata: responseCacheMetadata,
|
|
409
|
-
data: responseData
|
|
376
|
+
data: responseData,
|
|
377
|
+
hasNext
|
|
410
378
|
};
|
|
411
379
|
}
|
|
412
380
|
|
|
413
381
|
async resolveRequest(requestData, rawResponseData, options, context) {
|
|
414
|
-
|
|
382
|
+
const cacheManagerContext = { ...context,
|
|
383
|
+
fragmentDefinitions: (0, _helpers.getFragmentDefinitions)(requestData.ast),
|
|
384
|
+
typeIDKey: this._typeIDKey
|
|
385
|
+
};
|
|
386
|
+
return this._resolveRequest(requestData, rawResponseData, options, cacheManagerContext);
|
|
415
387
|
}
|
|
416
388
|
|
|
417
|
-
async
|
|
418
|
-
if ((0, _helpers.hasChildFields)(
|
|
419
|
-
await this.
|
|
389
|
+
async _analyzeFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
390
|
+
if ((0, _helpers.hasChildFields)(fieldNode)) {
|
|
391
|
+
await this._analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
|
|
420
392
|
} else {
|
|
421
|
-
await
|
|
393
|
+
await this._analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
|
|
422
394
|
}
|
|
423
395
|
}
|
|
424
396
|
|
|
425
|
-
async
|
|
426
|
-
const keysAndPaths =
|
|
427
|
-
|
|
397
|
+
async _analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
398
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(fieldNode, cachedAncestorFieldData, context);
|
|
428
399
|
const {
|
|
429
400
|
hashedRequestFieldCacheKey,
|
|
430
401
|
propNameOrIndex,
|
|
431
|
-
requestFieldCacheKey,
|
|
432
402
|
requestFieldPath
|
|
433
403
|
} = keysAndPaths;
|
|
434
404
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
435
405
|
const {
|
|
436
|
-
|
|
437
|
-
|
|
406
|
+
entityData,
|
|
407
|
+
fragmentKind,
|
|
408
|
+
fragmentName,
|
|
409
|
+
requestFieldPathData,
|
|
438
410
|
typeName
|
|
439
411
|
} = cachedAncestorFieldData;
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
412
|
+
const typeNamesAndKind = {
|
|
413
|
+
dataTypeName: (entityData === null || entityData === void 0 ? void 0 : entityData.__typename) || (requestFieldPathData === null || requestFieldPathData === void 0 ? void 0 : requestFieldPathData.__typename),
|
|
414
|
+
fieldTypeName: typeName,
|
|
415
|
+
fragmentKind,
|
|
416
|
+
fragmentName
|
|
443
417
|
};
|
|
444
418
|
|
|
445
|
-
if (CacheManager.
|
|
446
|
-
|
|
447
|
-
|
|
419
|
+
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
420
|
+
const {
|
|
421
|
+
cacheability,
|
|
422
|
+
entry
|
|
423
|
+
} = await this._retrieveCachedRequestFieldPathData(hashedRequestFieldCacheKey, options, context);
|
|
424
|
+
|
|
425
|
+
CacheManager._setCachedResponseData({
|
|
426
|
+
cacheability,
|
|
427
|
+
data: entry
|
|
428
|
+
}, cachedResponseData, keysAndPaths, typeNamesAndKind, options, context);
|
|
429
|
+
} else {
|
|
430
|
+
const cachedFieldData = CacheManager._getFieldDataFromAncestor(entityData, propNameOrIndex) || CacheManager._getFieldDataFromAncestor(requestFieldPathData, propNameOrIndex);
|
|
431
|
+
|
|
432
|
+
CacheManager._setFieldPathChecklist(cachedResponseData.fieldPathChecklist, {
|
|
433
|
+
data: cachedFieldData
|
|
434
|
+
}, requestFieldPath, typeNamesAndKind);
|
|
448
435
|
|
|
449
|
-
|
|
450
|
-
|
|
436
|
+
CacheManager._setCachedData(cachedResponseData.data, {
|
|
437
|
+
data: cachedFieldData
|
|
438
|
+
}, propNameOrIndex);
|
|
451
439
|
}
|
|
440
|
+
}
|
|
452
441
|
|
|
442
|
+
async _analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context) {
|
|
443
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(fieldNode, cachedAncestorFieldData, context);
|
|
444
|
+
const {
|
|
445
|
+
propNameOrIndex,
|
|
446
|
+
requestFieldCacheKey,
|
|
447
|
+
requestFieldPath
|
|
448
|
+
} = keysAndPaths;
|
|
449
|
+
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
453
450
|
const {
|
|
454
451
|
cacheability,
|
|
455
|
-
|
|
452
|
+
data,
|
|
453
|
+
entityData,
|
|
456
454
|
requestFieldPathData
|
|
457
|
-
} =
|
|
458
|
-
const
|
|
455
|
+
} = await this._retrieveCachedParentNodeData(cachedAncestorFieldData, keysAndPaths, fieldTypeInfo, options, context);
|
|
456
|
+
const {
|
|
457
|
+
fragmentKind,
|
|
458
|
+
fragmentName,
|
|
459
|
+
typeName
|
|
460
|
+
} = cachedAncestorFieldData;
|
|
459
461
|
|
|
460
462
|
CacheManager._setCachedResponseData({
|
|
461
463
|
cacheability,
|
|
462
464
|
data
|
|
463
465
|
}, cachedResponseData, keysAndPaths, {
|
|
464
466
|
dataTypeName: (0, _get2.default)(data, _core.TYPE_NAME_KEY),
|
|
465
|
-
fieldTypeName: typeName
|
|
467
|
+
fieldTypeName: typeName,
|
|
468
|
+
fragmentKind,
|
|
469
|
+
fragmentName
|
|
466
470
|
}, options, context);
|
|
467
471
|
|
|
468
|
-
if (!(0, _isObjectLike2.default)(data))
|
|
472
|
+
if (!(0, _isObjectLike2.default)(data)) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
|
|
469
476
|
const objectLikeData = data;
|
|
470
477
|
const promises = [];
|
|
471
|
-
(0, _helpers.iterateChildFields)(
|
|
472
|
-
promises.push(this.
|
|
478
|
+
(0, _helpers.iterateChildFields)(fieldNode, objectLikeData, context.fragmentDefinitions, (childField, childTypeName, childFragmentKind, childFragmentName, childIndex) => {
|
|
479
|
+
promises.push(this._analyzeFieldNode(childField, {
|
|
480
|
+
cacheability,
|
|
481
|
+
entityData,
|
|
482
|
+
fragmentKind: childFragmentKind,
|
|
483
|
+
fragmentName: childFragmentName,
|
|
473
484
|
index: childIndex,
|
|
474
485
|
requestFieldCacheKey,
|
|
475
486
|
requestFieldPath,
|
|
476
|
-
|
|
477
|
-
|
|
487
|
+
requestFieldPathData,
|
|
488
|
+
typeName: childTypeName
|
|
478
489
|
}, { ...cachedResponseData,
|
|
479
490
|
data: cachedResponseData.data[propNameOrIndex]
|
|
480
491
|
}, options, context));
|
|
@@ -495,7 +506,11 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
495
506
|
|
|
496
507
|
const queryNode = (0, _helpers.getOperationDefinitions)(ast, context.operation)[0];
|
|
497
508
|
const fieldsAndTypeNames = (0, _helpers.getChildFields)(queryNode);
|
|
498
|
-
|
|
509
|
+
|
|
510
|
+
if (!fieldsAndTypeNames) {
|
|
511
|
+
return cacheMetadata;
|
|
512
|
+
}
|
|
513
|
+
|
|
499
514
|
fieldsAndTypeNames.forEach(({
|
|
500
515
|
fieldNode
|
|
501
516
|
}) => this._setFieldCacheability(fieldNode, {
|
|
@@ -510,9 +525,17 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
510
525
|
async _checkCacheEntry(cacheType, hash, options, context) {
|
|
511
526
|
try {
|
|
512
527
|
const cacheability = await this._hasCacheEntry(cacheType, hash);
|
|
513
|
-
|
|
528
|
+
|
|
529
|
+
if (!cacheability || !CacheManager._isValid(cacheability)) {
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
|
|
514
533
|
const entry = await this._getCacheEntry(cacheType, hash, options, context);
|
|
515
|
-
|
|
534
|
+
|
|
535
|
+
if ((0, _isUndefined2.default)(entry)) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
|
|
516
539
|
return {
|
|
517
540
|
cacheability,
|
|
518
541
|
entry
|
|
@@ -543,148 +566,6 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
543
566
|
return cacheMetadata;
|
|
544
567
|
}
|
|
545
568
|
|
|
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
569
|
async _getCacheEntry(cacheType, hash, _options, _context) {
|
|
689
570
|
try {
|
|
690
571
|
return await this._cache.get(`${cacheType}::${hash}`);
|
|
@@ -702,7 +583,10 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
702
583
|
}
|
|
703
584
|
|
|
704
585
|
_getResponseData(responseData, partialQueryResponse) {
|
|
705
|
-
if (!partialQueryResponse)
|
|
586
|
+
if (!partialQueryResponse) {
|
|
587
|
+
return responseData;
|
|
588
|
+
}
|
|
589
|
+
|
|
706
590
|
return this._mergeObjects(partialQueryResponse.data, responseData);
|
|
707
591
|
}
|
|
708
592
|
|
|
@@ -718,9 +602,18 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
718
602
|
isEntity,
|
|
719
603
|
possibleTypes
|
|
720
604
|
}) {
|
|
721
|
-
if (!(0, _get2.default)(fieldData, this._typeIDKey, null))
|
|
722
|
-
|
|
723
|
-
|
|
605
|
+
if (!(0, _get2.default)(fieldData, this._typeIDKey, null)) {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (isEntity) {
|
|
610
|
+
return true;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (!possibleTypes.length) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
|
|
724
617
|
return possibleTypes.some(type => type.typeName === fieldData.__typename);
|
|
725
618
|
}
|
|
726
619
|
|
|
@@ -730,126 +623,79 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
730
623
|
});
|
|
731
624
|
}
|
|
732
625
|
|
|
733
|
-
async
|
|
626
|
+
async _parseEntityAndRequestFieldPathCacheEntryData(field, ancestorKeysAndPaths, {
|
|
734
627
|
cacheMetadata,
|
|
735
|
-
|
|
628
|
+
entityData,
|
|
736
629
|
requestFieldPathData
|
|
737
630
|
}, options, context) {
|
|
738
|
-
const keysAndPaths =
|
|
739
|
-
|
|
631
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(field, ancestorKeysAndPaths, context);
|
|
740
632
|
const {
|
|
741
633
|
requestFieldCacheKey,
|
|
742
634
|
requestFieldPath,
|
|
743
635
|
responseDataPath
|
|
744
636
|
} = 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
|
-
|
|
637
|
+
const fieldData = (0, _get2.default)(requestFieldPathData, responseDataPath);
|
|
638
|
+
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
639
|
+
|
|
640
|
+
if (!(0, _isObjectLike2.default)(fieldData) && !(fieldTypeInfo !== null && fieldTypeInfo !== void 0 && fieldTypeInfo.hasDirectives)) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
if ((0, _isObjectLike2.default)(fieldData)) {
|
|
645
|
+
const promises = [];
|
|
646
|
+
(0, _helpers.iterateChildFields)(field, fieldData, context.fragmentDefinitions, (childField, _typeName, _fragmentKind, _fragmentName, childIndex) => {
|
|
647
|
+
promises.push(this._parseEntityAndRequestFieldPathCacheEntryData(childField, {
|
|
648
|
+
index: childIndex,
|
|
649
|
+
requestFieldCacheKey,
|
|
650
|
+
requestFieldPath,
|
|
651
|
+
responseDataPath
|
|
652
|
+
}, {
|
|
653
|
+
cacheMetadata,
|
|
654
|
+
entityData,
|
|
655
|
+
requestFieldPathData
|
|
656
|
+
}, options, context));
|
|
657
|
+
});
|
|
658
|
+
await Promise.all(promises);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
await this._setEntityAndRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
763
662
|
cacheMetadata,
|
|
764
|
-
|
|
663
|
+
entityData,
|
|
765
664
|
requestFieldPathData
|
|
766
665
|
}, options, context);
|
|
767
666
|
}
|
|
768
667
|
|
|
769
668
|
async _resolveRequest(requestData, rawResponseData, options, context) {
|
|
669
|
+
const normalizedResponseData = rawResponseData.path ? (0, _normalizeResponseData.default)(rawResponseData) : rawResponseData;
|
|
770
670
|
const dataCaching = [];
|
|
771
671
|
|
|
772
|
-
const cacheMetadata = this._buildCacheMetadata(requestData,
|
|
672
|
+
const cacheMetadata = this._buildCacheMetadata(requestData, normalizedResponseData, options, context);
|
|
773
673
|
|
|
774
674
|
const {
|
|
775
|
-
data
|
|
776
|
-
|
|
777
|
-
|
|
675
|
+
data,
|
|
676
|
+
hasNext
|
|
677
|
+
} = normalizedResponseData;
|
|
678
|
+
dataCaching.push(this._setEntityAndRequestFieldPathCacheEntries(requestData, {
|
|
778
679
|
cacheMetadata,
|
|
779
|
-
|
|
680
|
+
entityData: (0, _cloneDeep2.default)(data),
|
|
780
681
|
requestFieldPathData: (0, _cloneDeep2.default)(data)
|
|
781
682
|
}, 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
683
|
|
|
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);
|
|
684
|
+
if (options.awaitDataCaching) {
|
|
685
|
+
await Promise.all(dataCaching);
|
|
822
686
|
}
|
|
823
687
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
if (result) {
|
|
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
|
-
}
|
|
688
|
+
return {
|
|
689
|
+
cacheMetadata,
|
|
690
|
+
data,
|
|
691
|
+
hasNext
|
|
692
|
+
};
|
|
843
693
|
}
|
|
844
694
|
|
|
845
|
-
async
|
|
695
|
+
async _retrieveCachedEntityData(validTypeIDValue, {
|
|
846
696
|
possibleTypes,
|
|
847
|
-
typeIDValue,
|
|
848
697
|
typeName
|
|
849
698
|
}, 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
699
|
const typeNames = [...possibleTypes.map(type => type.typeName), typeName];
|
|
854
700
|
const checkResults = await Promise.all(typeNames.map(name => this._checkCacheEntry(_core.DATA_ENTITIES, `${name}::${validTypeIDValue}`, options, context)));
|
|
855
701
|
const validResults = checkResults.filter(result => !!result);
|
|
@@ -871,76 +717,228 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
871
717
|
};
|
|
872
718
|
}
|
|
873
719
|
|
|
874
|
-
|
|
720
|
+
return validResult || {};
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
async _retrieveCachedParentNodeData({
|
|
724
|
+
entityData: ancestorEntityData,
|
|
725
|
+
requestFieldPathData: ancestorRequestFieldPathData
|
|
726
|
+
}, {
|
|
727
|
+
hashedRequestFieldCacheKey,
|
|
728
|
+
propNameOrIndex
|
|
729
|
+
}, fieldTypeInfo, options, context) {
|
|
730
|
+
var _entityData;
|
|
731
|
+
|
|
732
|
+
let entityData = CacheManager._getFieldDataFromAncestor(ancestorEntityData, propNameOrIndex);
|
|
733
|
+
|
|
734
|
+
let requestFieldPathData = CacheManager._getFieldDataFromAncestor(ancestorRequestFieldPathData, propNameOrIndex);
|
|
735
|
+
|
|
736
|
+
let cacheability;
|
|
737
|
+
|
|
738
|
+
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
875
739
|
const {
|
|
876
|
-
cacheability,
|
|
740
|
+
cacheability: entryCacheability,
|
|
877
741
|
entry
|
|
878
|
-
} =
|
|
879
|
-
|
|
880
|
-
if (entry)
|
|
742
|
+
} = await this._retrieveCachedRequestFieldPathData(hashedRequestFieldCacheKey, options, context);
|
|
743
|
+
|
|
744
|
+
if (entry) {
|
|
745
|
+
requestFieldPathData = this._mergeObjects(requestFieldPathData, entry);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
if (entryCacheability) {
|
|
749
|
+
cacheability = entryCacheability;
|
|
750
|
+
}
|
|
881
751
|
}
|
|
752
|
+
|
|
753
|
+
const validTypeIDValue = (0, _validTypeIDValue.getValidTypeIDValue)(requestFieldPathData, fieldTypeInfo, this._typeIDKey);
|
|
754
|
+
|
|
755
|
+
if (CacheManager._isNodeEntity(fieldTypeInfo) && validTypeIDValue) {
|
|
756
|
+
var _cacheability;
|
|
757
|
+
|
|
758
|
+
const {
|
|
759
|
+
cacheability: entryCacheability,
|
|
760
|
+
entry
|
|
761
|
+
} = await this._retrieveCachedEntityData(validTypeIDValue, fieldTypeInfo, options, context);
|
|
762
|
+
|
|
763
|
+
if (entry) {
|
|
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))) {
|
|
768
|
+
cacheability = entryCacheability;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const data = !(0, _isUndefined2.default)(requestFieldPathData) || !(0, _isUndefined2.default)(entityData) ? this._mergeObjects(requestFieldPathData, entityData) : (_entityData = entityData) !== null && _entityData !== void 0 ? _entityData : requestFieldPathData;
|
|
773
|
+
return {
|
|
774
|
+
cacheability,
|
|
775
|
+
data,
|
|
776
|
+
entityData,
|
|
777
|
+
requestFieldPathData
|
|
778
|
+
};
|
|
882
779
|
}
|
|
883
780
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
781
|
+
async _retrieveCachedRequestFieldPathData(hash, options, context) {
|
|
782
|
+
return this._checkCacheEntry(_core.REQUEST_FIELD_PATHS, hash, options, context) || {};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
async _retrieveCachedResponseData({
|
|
786
|
+
ast
|
|
887
787
|
}, options, context) {
|
|
888
|
-
const {
|
|
889
|
-
|
|
890
|
-
|
|
788
|
+
const cachedResponseData = {
|
|
789
|
+
cacheMetadata: new Map(),
|
|
790
|
+
data: {},
|
|
791
|
+
fieldCount: {
|
|
792
|
+
missing: 0,
|
|
793
|
+
total: 0
|
|
794
|
+
},
|
|
795
|
+
fieldPathChecklist: new Map()
|
|
796
|
+
};
|
|
797
|
+
const queryNode = (0, _helpers.getOperationDefinitions)(ast, context.operation)[0];
|
|
798
|
+
const fieldsAndTypeNames = (0, _helpers.getChildFields)(queryNode);
|
|
891
799
|
|
|
892
|
-
|
|
800
|
+
if (!fieldsAndTypeNames) {
|
|
801
|
+
return cachedResponseData;
|
|
802
|
+
}
|
|
893
803
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
804
|
+
await Promise.all(fieldsAndTypeNames.map(({
|
|
805
|
+
fieldNode
|
|
806
|
+
}) => this._analyzeFieldNode(fieldNode, {
|
|
807
|
+
requestFieldPath: context.operation
|
|
808
|
+
}, cachedResponseData, options, context)));
|
|
809
|
+
cachedResponseData.fieldCount = CacheManager._countFieldPathChecklist(cachedResponseData.fieldPathChecklist);
|
|
810
|
+
return cachedResponseData;
|
|
811
|
+
}
|
|
901
812
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
813
|
+
async _setCacheEntry(cacheType, hash, value, cachemapOptions, _options, _context) {
|
|
814
|
+
try {
|
|
815
|
+
await this._cache.set(`${cacheType}::${hash}`, (0, _cloneDeep2.default)(value), cachemapOptions);
|
|
816
|
+
} catch (error) {}
|
|
817
|
+
}
|
|
906
818
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
819
|
+
async _setEntityAndRequestFieldPathCacheEntries(requestData, responseData, options, context) {
|
|
820
|
+
const operationNode = (0, _helpers.getOperationDefinitions)(requestData.ast, context.operation)[0];
|
|
821
|
+
const fieldsAndTypeNames = (0, _helpers.getChildFields)(operationNode);
|
|
822
|
+
|
|
823
|
+
if (!fieldsAndTypeNames) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
await Promise.all(fieldsAndTypeNames.map(({
|
|
828
|
+
fieldNode
|
|
829
|
+
}) => {
|
|
830
|
+
return this._parseEntityAndRequestFieldPathCacheEntryData(fieldNode, {
|
|
831
|
+
requestFieldPath: context.operation
|
|
832
|
+
}, responseData, options, context);
|
|
833
|
+
}));
|
|
917
834
|
}
|
|
918
835
|
|
|
919
|
-
async
|
|
836
|
+
async _setEntityAndRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
920
837
|
cacheMetadata,
|
|
921
|
-
|
|
838
|
+
entityData,
|
|
922
839
|
requestFieldPathData
|
|
923
840
|
}, options, context) {
|
|
924
841
|
const {
|
|
925
|
-
requestFieldPath
|
|
842
|
+
requestFieldPath,
|
|
843
|
+
responseDataPath
|
|
926
844
|
} = keysAndPaths;
|
|
845
|
+
const fieldData = (0, _get2.default)(entityData, responseDataPath);
|
|
927
846
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
928
847
|
const cacheability = cacheMetadata.get(requestFieldPath);
|
|
929
|
-
|
|
848
|
+
|
|
849
|
+
if ((0, _isUndefined2.default)(fieldData) || !fieldTypeInfo || !cacheability) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
|
|
930
853
|
const promises = [];
|
|
931
854
|
promises.push(this._setRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
932
855
|
cacheability,
|
|
933
856
|
data: requestFieldPathData,
|
|
934
857
|
fieldTypeInfo
|
|
935
858
|
}, options, context));
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
859
|
+
|
|
860
|
+
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
861
|
+
|
|
862
|
+
if (!isEntity && fieldTypeInfo.hasArguments) {
|
|
863
|
+
(0, _unset2.default)(entityData, responseDataPath);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
if (isEntity) {
|
|
867
|
+
promises.push(this._setEntityCacheEntry(keysAndPaths, {
|
|
868
|
+
cacheability,
|
|
869
|
+
data: entityData,
|
|
870
|
+
fieldTypeInfo
|
|
871
|
+
}, options, context));
|
|
872
|
+
}
|
|
873
|
+
|
|
941
874
|
await Promise.all(promises);
|
|
942
875
|
}
|
|
943
876
|
|
|
877
|
+
async _setEntityCacheEntry({
|
|
878
|
+
responseDataPath
|
|
879
|
+
}, {
|
|
880
|
+
cacheability,
|
|
881
|
+
data,
|
|
882
|
+
fieldTypeInfo
|
|
883
|
+
}, options, context) {
|
|
884
|
+
let fieldData = (0, _get2.default)(data, responseDataPath);
|
|
885
|
+
const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
|
|
886
|
+
const entityDataKey = `${fieldTypeName}::${fieldData[this._typeIDKey]}`;
|
|
887
|
+
const result = await this._checkCacheEntry(_core.DATA_ENTITIES, entityDataKey, options, context);
|
|
888
|
+
|
|
889
|
+
if (result) {
|
|
890
|
+
fieldData = this._mergeObjects(result.entry, fieldData);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
await this._setCacheEntry(_core.DATA_ENTITIES, entityDataKey, fieldData, {
|
|
894
|
+
cacheHeaders: {
|
|
895
|
+
cacheControl: cacheability.printCacheControl()
|
|
896
|
+
},
|
|
897
|
+
tag: options.tag
|
|
898
|
+
}, options, context);
|
|
899
|
+
(0, _set2.default)(data, responseDataPath, {
|
|
900
|
+
__cacheKey: `${_core.DATA_ENTITIES}::${entityDataKey}`
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
_setFieldCacheability(field, ancestorKeysAndPaths, {
|
|
905
|
+
cacheMetadata,
|
|
906
|
+
data
|
|
907
|
+
}, options, context) {
|
|
908
|
+
const {
|
|
909
|
+
requestFieldPath: ancestorRequestFieldPath
|
|
910
|
+
} = ancestorKeysAndPaths;
|
|
911
|
+
const keysAndPaths = (0, _buildKeysAndPaths.buildFieldKeysAndPaths)(field, ancestorKeysAndPaths, context);
|
|
912
|
+
const {
|
|
913
|
+
requestFieldPath,
|
|
914
|
+
responseDataPath
|
|
915
|
+
} = keysAndPaths;
|
|
916
|
+
const fieldData = (0, _get2.default)(data, responseDataPath);
|
|
917
|
+
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
918
|
+
|
|
919
|
+
if (!(0, _isObjectLike2.default)(fieldData) && !(fieldTypeInfo !== null && fieldTypeInfo !== void 0 && fieldTypeInfo.hasDirectives)) {
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
this._setFieldTypeCacheDirective(cacheMetadata, {
|
|
924
|
+
ancestorRequestFieldPath,
|
|
925
|
+
requestFieldPath
|
|
926
|
+
}, context);
|
|
927
|
+
|
|
928
|
+
if ((0, _isObjectLike2.default)(fieldData)) {
|
|
929
|
+
(0, _helpers.iterateChildFields)(field, fieldData, context.fragmentDefinitions, (childField, _typeName, _fragmentKind, _fragmentName, childIndex) => {
|
|
930
|
+
this._setFieldCacheability(childField, {
|
|
931
|
+
index: childIndex,
|
|
932
|
+
requestFieldPath,
|
|
933
|
+
responseDataPath
|
|
934
|
+
}, {
|
|
935
|
+
cacheMetadata,
|
|
936
|
+
data
|
|
937
|
+
}, options, context);
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
944
942
|
_setFieldTypeCacheDirective(cacheMetadata, {
|
|
945
943
|
ancestorRequestFieldPath,
|
|
946
944
|
requestFieldPath
|
|
@@ -948,11 +946,14 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
948
946
|
fieldTypeMap,
|
|
949
947
|
operation
|
|
950
948
|
}) {
|
|
951
|
-
if (cacheMetadata.has(requestFieldPath))
|
|
949
|
+
if (cacheMetadata.has(requestFieldPath)) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
|
|
952
953
|
const fieldTypeInfo = fieldTypeMap.get(requestFieldPath);
|
|
953
954
|
|
|
954
955
|
if (fieldTypeInfo && this._typeCacheDirectives[fieldTypeInfo.typeName]) {
|
|
955
|
-
const cacheability = new
|
|
956
|
+
const cacheability = new _cacheability2.default({
|
|
956
957
|
cacheControl: this._typeCacheDirectives[fieldTypeInfo.typeName]
|
|
957
958
|
});
|
|
958
959
|
|
|
@@ -985,23 +986,31 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
985
986
|
}, options, context);
|
|
986
987
|
}
|
|
987
988
|
|
|
988
|
-
async _setRequestFieldPathCacheEntry(field, {
|
|
989
|
-
hashedRequestFieldCacheKey,
|
|
990
|
-
responseDataPath
|
|
991
|
-
}, {
|
|
989
|
+
async _setRequestFieldPathCacheEntry(field, keysAndPaths, {
|
|
992
990
|
cacheability,
|
|
993
991
|
data,
|
|
994
992
|
fieldTypeInfo
|
|
995
993
|
}, options, context) {
|
|
996
|
-
const
|
|
997
|
-
|
|
994
|
+
const {
|
|
995
|
+
hashedRequestFieldCacheKey,
|
|
996
|
+
responseDataPath
|
|
997
|
+
} = keysAndPaths;
|
|
998
|
+
let fieldData = (0, _get2.default)(data, responseDataPath);
|
|
998
999
|
|
|
999
1000
|
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
1000
1001
|
|
|
1002
|
+
const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
|
|
1003
|
+
|
|
1001
1004
|
if (context.operation === _core.QUERY && (isEntity || hasArgsOrDirectives)) {
|
|
1005
|
+
var _field$selectionSet;
|
|
1006
|
+
|
|
1007
|
+
if ((0, _isPlainObject2.default)(fieldData) && (_field$selectionSet = field.selectionSet) !== null && _field$selectionSet !== void 0 && _field$selectionSet.selections) {
|
|
1008
|
+
fieldData = (0, _filterOutPropsWithArgsOrDirectives.default)(fieldData, field.selectionSet.selections, keysAndPaths, context);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1002
1011
|
const result = await this._checkCacheEntry(_core.REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, context);
|
|
1003
1012
|
|
|
1004
|
-
if (result) {
|
|
1013
|
+
if (result && (0, _isObjectLike2.default)(fieldData)) {
|
|
1005
1014
|
fieldData = this._mergeObjects(result.entry, fieldData);
|
|
1006
1015
|
}
|
|
1007
1016
|
|
|
@@ -1024,19 +1033,6 @@ let CacheManager = (_dec = (0, _debug.logCacheQuery)(), _dec2 = (0, _debug.logCa
|
|
|
1024
1033
|
}
|
|
1025
1034
|
}
|
|
1026
1035
|
|
|
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
1036
|
}, ((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
1037
|
exports.CacheManager = CacheManager;
|
|
1042
1038
|
|