@graphql-box/cache-manager 3.4.1 → 3.4.3
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 +33 -24
- package/lib/main/helpers/areOnlyPopulatedFieldsTypeIdKeys.js +53 -0
- package/lib/main/helpers/areOnlyPopulatedFieldsTypeIdKeys.js.map +1 -0
- package/lib/main/main/index.js +3 -1
- package/lib/main/main/index.js.map +1 -1
- package/lib/module/helpers/areOnlyPopulatedFieldsTypeIdKeys.js +41 -0
- package/lib/module/helpers/areOnlyPopulatedFieldsTypeIdKeys.js.map +1 -0
- package/lib/module/main/index.js +2 -1
- package/lib/module/main/index.js.map +1 -1
- package/lib/types/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts +4 -0
- package/lib/types/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts.map +1 -0
- package/lib/types/main/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__snapshots__/index.test.ts.snap +131 -0
- package/src/helpers/areOnlyPopulatedFieldsTypeIdKeys.ts +40 -0
- package/src/index.test.ts +54 -0
- package/src/main/index.ts +5 -1
package/src/index.test.ts
CHANGED
|
@@ -1200,6 +1200,60 @@ describe("@graphql-box/cache-manager >>", () => {
|
|
|
1200
1200
|
});
|
|
1201
1201
|
});
|
|
1202
1202
|
|
|
1203
|
+
describe("single type with just ID match >>", () => {
|
|
1204
|
+
beforeAll(async () => {
|
|
1205
|
+
analyzeQueryResult = undefined;
|
|
1206
|
+
// @ts-ignore
|
|
1207
|
+
jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
|
|
1208
|
+
|
|
1209
|
+
cacheManager = new CacheManager({
|
|
1210
|
+
cache: new Cachemap({
|
|
1211
|
+
name: "cachemap",
|
|
1212
|
+
store: map(),
|
|
1213
|
+
type: "someType",
|
|
1214
|
+
}),
|
|
1215
|
+
typeCacheDirectives: {
|
|
1216
|
+
Organization: "public, max-age=1",
|
|
1217
|
+
},
|
|
1218
|
+
typeIDKey: DEFAULT_TYPE_ID_KEY,
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
const requestData = getRequestData(parsedRequests.singleTypeQuerySmallA);
|
|
1222
|
+
|
|
1223
|
+
await cacheManager.cacheQuery(
|
|
1224
|
+
requestData,
|
|
1225
|
+
requestData,
|
|
1226
|
+
responses.singleTypeQuerySmallA,
|
|
1227
|
+
{ awaitDataCaching: true },
|
|
1228
|
+
getRequestContext({ fieldTypeMap: requestFieldTypeMaps.singleTypeQuery }),
|
|
1229
|
+
);
|
|
1230
|
+
|
|
1231
|
+
analyzeQueryResult = await cacheManager.analyzeQuery(
|
|
1232
|
+
getRequestData(parsedRequests.singleTypeQuerySmallB),
|
|
1233
|
+
{ awaitDataCaching: true },
|
|
1234
|
+
getRequestContext({ fieldTypeMap: requestFieldTypeMaps.singleTypeQuery }),
|
|
1235
|
+
);
|
|
1236
|
+
});
|
|
1237
|
+
|
|
1238
|
+
it("correct request data", () => {
|
|
1239
|
+
const { ast, ...otherProps } = analyzeQueryResult?.updated as RequestData;
|
|
1240
|
+
expect(otherProps).toMatchSnapshot();
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
it("no response data", () => {
|
|
1244
|
+
expect(analyzeQueryResult?.response).toBeUndefined();
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
it("correct cache data", async () => {
|
|
1248
|
+
expect(await cacheManager.cache.export()).toMatchSnapshot();
|
|
1249
|
+
});
|
|
1250
|
+
|
|
1251
|
+
it("correct partial data", () => {
|
|
1252
|
+
// @ts-ignore
|
|
1253
|
+
expect(cacheManager._partialQueryResponses).toMatchSnapshot();
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
|
|
1203
1257
|
describe("nested type with edges >", () => {
|
|
1204
1258
|
beforeAll(async () => {
|
|
1205
1259
|
analyzeQueryResult = undefined;
|
package/src/main/index.ts
CHANGED
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
TypeNamesAndKind,
|
|
60
60
|
UserOptions,
|
|
61
61
|
} from "../defs";
|
|
62
|
+
import areOnlyPopulatedFieldsTypeIdKeys from "../helpers/areOnlyPopulatedFieldsTypeIdKeys";
|
|
62
63
|
import deriveOpCacheability from "../helpers/deriveOpCacheability";
|
|
63
64
|
import filterOutPropsWithArgsOrDirectives from "../helpers/filterOutPropsWithArgsOrDirectives";
|
|
64
65
|
import filterQuery from "../helpers/filterQuery";
|
|
@@ -260,7 +261,10 @@ export class CacheManager implements CacheManagerDef {
|
|
|
260
261
|
const cachedResponseData = await this._retrieveCachedResponseData(requestData, options, cacheManagerContext);
|
|
261
262
|
const { cacheMetadata, data, fieldCount } = cachedResponseData;
|
|
262
263
|
|
|
263
|
-
|
|
264
|
+
// Second half of check is required for the scenario where the only matching data is
|
|
265
|
+
// the typeIDKey field, i.e. "id", in which case there is no point settings a partial
|
|
266
|
+
// query reponse because we request the typeIDKey field with every request.
|
|
267
|
+
if (fieldCount.missing === fieldCount.total || areOnlyPopulatedFieldsTypeIdKeys(data, this._typeIDKey)) {
|
|
264
268
|
return { updated: requestData };
|
|
265
269
|
}
|
|
266
270
|
|