@graphql-box/cache-manager 3.0.0 → 3.1.2
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 +32 -32
- package/lib/main/helpers/createFragmentSpreadChecklist.js +5 -2
- package/lib/main/helpers/createFragmentSpreadChecklist.js.map +1 -1
- package/lib/main/helpers/filterField.js.map +1 -1
- package/lib/main/helpers/filterFragmentDefinitions.js +5 -0
- package/lib/main/helpers/filterFragmentDefinitions.js.map +1 -1
- package/lib/main/helpers/filterFragmentSpreads.js +0 -1
- package/lib/main/helpers/filterFragmentSpreads.js.map +1 -1
- package/lib/main/helpers/filterIDsAndTypeNames.js.map +1 -1
- package/lib/main/helpers/filterInlineFragments.js.map +1 -1
- package/lib/main/helpers/filterOperationAndFragmentDefinitions.js +15 -0
- package/lib/main/helpers/filterOperationAndFragmentDefinitions.js.map +1 -0
- package/lib/main/helpers/filterQuery.js +5 -4
- package/lib/main/helpers/filterQuery.js.map +1 -1
- package/lib/module/helpers/createFragmentSpreadChecklist.js +5 -2
- package/lib/module/helpers/createFragmentSpreadChecklist.js.map +1 -1
- package/lib/module/helpers/filterField.js.map +1 -1
- package/lib/module/helpers/filterFragmentDefinitions.js +4 -0
- package/lib/module/helpers/filterFragmentDefinitions.js.map +1 -1
- package/lib/module/helpers/filterFragmentSpreads.js +0 -1
- package/lib/module/helpers/filterFragmentSpreads.js.map +1 -1
- package/lib/module/helpers/filterIDsAndTypeNames.js.map +1 -1
- package/lib/module/helpers/filterInlineFragments.js.map +1 -1
- package/lib/module/helpers/filterOperationAndFragmentDefinitions.js +5 -0
- package/lib/module/helpers/filterOperationAndFragmentDefinitions.js.map +1 -0
- package/lib/module/helpers/filterQuery.js +5 -4
- package/lib/module/helpers/filterQuery.js.map +1 -1
- package/lib/types/defs/index.d.ts +2 -1
- package/lib/types/defs/index.d.ts.map +1 -1
- package/lib/types/helpers/createFragmentSpreadChecklist.d.ts +2 -2
- package/lib/types/helpers/createFragmentSpreadChecklist.d.ts.map +1 -1
- package/lib/types/helpers/filterField.d.ts +2 -2
- package/lib/types/helpers/filterField.d.ts.map +1 -1
- package/lib/types/helpers/filterFragmentDefinitions.d.ts +1 -5
- package/lib/types/helpers/filterFragmentDefinitions.d.ts.map +1 -1
- package/lib/types/helpers/filterFragmentSpreads.d.ts +2 -2
- package/lib/types/helpers/filterFragmentSpreads.d.ts.map +1 -1
- package/lib/types/helpers/filterIDsAndTypeNames.d.ts +2 -2
- package/lib/types/helpers/filterIDsAndTypeNames.d.ts.map +1 -1
- package/lib/types/helpers/filterInlineFragments.d.ts +2 -2
- package/lib/types/helpers/filterInlineFragments.d.ts.map +1 -1
- package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts +4 -0
- package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts.map +1 -0
- package/lib/types/helpers/filterQuery.d.ts +1 -1
- package/lib/types/helpers/filterQuery.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/__snapshots__/index.test.ts.snap +25475 -0
- package/src/defs/index.ts +2 -1
- package/src/helpers/createFragmentSpreadChecklist.ts +3 -3
- package/src/helpers/filterField.ts +2 -2
- package/src/helpers/filterFragmentDefinitions.ts +4 -0
- package/src/helpers/filterFragmentSpreads.ts +2 -3
- package/src/helpers/filterIDsAndTypeNames.ts +5 -2
- package/src/helpers/filterInlineFragments.ts +5 -2
- package/src/helpers/filterOperationAndFragmentDefinitions.ts +10 -0
- package/src/helpers/filterQuery.ts +3 -2
- package/src/index.test.ts +52 -0
package/src/defs/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { RequestData } from "@graphql-box/core";
|
|
1
2
|
import { getFragmentDefinitions } from "@graphql-box/helpers";
|
|
2
|
-
import { DocumentNode } from "graphql";
|
|
3
3
|
import { keys } from "lodash";
|
|
4
4
|
|
|
5
5
|
export type FragmentSpreadCheckist = {
|
|
@@ -10,8 +10,8 @@ export type FragmentSpreadCheckist = {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export default (ast:
|
|
13
|
+
export default ({ ast, request }: RequestData) =>
|
|
14
14
|
keys(getFragmentDefinitions(ast) ?? {}).reduce((acc: FragmentSpreadCheckist, name) => {
|
|
15
|
-
acc[name] = { deleted: 0, paths: [], total:
|
|
15
|
+
acc[name] = { deleted: 0, paths: [], total: (request.match(new RegExp(`\\.\\.\\.${name}`, "g")) || []).length };
|
|
16
16
|
return acc;
|
|
17
17
|
}, {});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TYPE_NAME_KEY } from "@graphql-box/core";
|
|
2
2
|
import { FRAGMENT_SPREAD, deleteChildFields, getChildFields, getName, hasChildFields } from "@graphql-box/helpers";
|
|
3
|
-
import { FieldNode, FragmentDefinitionNode } from "graphql";
|
|
3
|
+
import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
|
|
4
4
|
import { CacheManagerContext, FieldPathChecklist, FragmentSpreadFieldCounter } from "../defs";
|
|
5
5
|
import { buildFieldKeysAndPaths } from "./buildKeysAndPaths";
|
|
6
6
|
import checkFieldPathChecklist from "./checkFieldPathChecklist";
|
|
@@ -10,7 +10,7 @@ import filterIDsAndTypeNames from "./filterIDsAndTypeNames";
|
|
|
10
10
|
import filterInlineFragments from "./filterInlineFragments";
|
|
11
11
|
|
|
12
12
|
const filterField = (
|
|
13
|
-
field: FieldNode | FragmentDefinitionNode,
|
|
13
|
+
field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
|
|
14
14
|
fieldPathChecklist: FieldPathChecklist,
|
|
15
15
|
fragmentSpreadChecklist: FragmentSpreadCheckist,
|
|
16
16
|
ancestorRequestFieldPath: string,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { deleteFragmentSpreads } from "@graphql-box/helpers";
|
|
2
|
-
import { FieldNode, FragmentDefinitionNode } from "graphql";
|
|
2
|
+
import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
|
|
3
3
|
import { isEmpty, keys } from "lodash";
|
|
4
4
|
import { FragmentSpreadFieldCounter } from "../defs";
|
|
5
5
|
import { FragmentSpreadCheckist } from "./createFragmentSpreadChecklist";
|
|
6
6
|
|
|
7
7
|
export default (
|
|
8
|
-
field: FieldNode | FragmentDefinitionNode,
|
|
8
|
+
field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
|
|
9
9
|
fragmentSpreadFieldCounter: FragmentSpreadFieldCounter,
|
|
10
10
|
fragmentSpreadChecklist: FragmentSpreadCheckist,
|
|
11
11
|
ancestorRequestFieldPath: string,
|
|
@@ -15,7 +15,6 @@ export default (
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
keys(fragmentSpreadFieldCounter).forEach(key => {
|
|
18
|
-
fragmentSpreadChecklist[key].total += 1;
|
|
19
18
|
fragmentSpreadChecklist[key].paths.push(ancestorRequestFieldPath);
|
|
20
19
|
|
|
21
20
|
const { hasData, total } = fragmentSpreadFieldCounter[key];
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { TYPE_NAME_KEY } from "@graphql-box/core";
|
|
2
2
|
import { deleteChildFields, getChildFields, getName } from "@graphql-box/helpers";
|
|
3
|
-
import { FieldNode, FragmentDefinitionNode } from "graphql";
|
|
3
|
+
import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
|
|
4
4
|
import { CacheManagerContext } from "../defs";
|
|
5
5
|
|
|
6
|
-
export default (
|
|
6
|
+
export default (
|
|
7
|
+
field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
|
|
8
|
+
{ fragmentDefinitions, typeIDKey }: CacheManagerContext,
|
|
9
|
+
) => {
|
|
7
10
|
const fieldsAndTypeNames = getChildFields(field, { fragmentDefinitions });
|
|
8
11
|
|
|
9
12
|
if (!fieldsAndTypeNames || fieldsAndTypeNames.length > 3) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { deleteInlineFragments, getChildFields, getInlineFragments, getName } from "@graphql-box/helpers";
|
|
2
|
-
import { FieldNode, FragmentDefinitionNode } from "graphql";
|
|
2
|
+
import { FieldNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
|
|
3
3
|
import { CacheManagerContext } from "..";
|
|
4
4
|
|
|
5
|
-
export default (
|
|
5
|
+
export default (
|
|
6
|
+
field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
|
|
7
|
+
{ fragmentDefinitions, typeIDKey }: CacheManagerContext,
|
|
8
|
+
) => {
|
|
6
9
|
const inlineFragments = getInlineFragments(field);
|
|
7
10
|
let filtered = false;
|
|
8
11
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FRAGMENT_DEFINITION, OPERATION_DEFINITION, isKind } from "@graphql-box/helpers";
|
|
2
|
+
import { DocumentNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
|
|
3
|
+
|
|
4
|
+
export default (ast: DocumentNode) => {
|
|
5
|
+
return ast.definitions.filter(
|
|
6
|
+
definition =>
|
|
7
|
+
isKind<OperationDefinitionNode>(definition, OPERATION_DEFINITION) ||
|
|
8
|
+
isKind<FragmentDefinitionNode>(definition, FRAGMENT_DEFINITION),
|
|
9
|
+
) as (OperationDefinitionNode | FragmentDefinitionNode)[];
|
|
10
|
+
};
|
|
@@ -6,7 +6,8 @@ import createFragmentSpreadChecklist from "./createFragmentSpreadChecklist";
|
|
|
6
6
|
import filterField from "./filterField";
|
|
7
7
|
import filterFragmentDefinitions from "./filterFragmentDefinitions";
|
|
8
8
|
|
|
9
|
-
export default (
|
|
9
|
+
export default (requestData: RequestData, { fieldPathChecklist }: CachedResponseData, context: CacheManagerContext) => {
|
|
10
|
+
const { ast } = requestData;
|
|
10
11
|
const queryNode = getOperationDefinitions(ast, context.operation)[0];
|
|
11
12
|
const { fragmentDefinitions } = context;
|
|
12
13
|
const fieldsAndTypeNames = getChildFields(queryNode, { fragmentDefinitions });
|
|
@@ -15,7 +16,7 @@ export default ({ ast }: RequestData, { fieldPathChecklist }: CachedResponseData
|
|
|
15
16
|
return ast;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
const fragmentSpreadChecklist = createFragmentSpreadChecklist(
|
|
19
|
+
const fragmentSpreadChecklist = createFragmentSpreadChecklist(requestData);
|
|
19
20
|
|
|
20
21
|
for (let i = fieldsAndTypeNames.length - 1; i >= 0; i -= 1) {
|
|
21
22
|
const { fieldNode } = fieldsAndTypeNames[i];
|
package/src/index.test.ts
CHANGED
|
@@ -1312,6 +1312,58 @@ describe("@graphql-box/cache-manager >>", () => {
|
|
|
1312
1312
|
});
|
|
1313
1313
|
});
|
|
1314
1314
|
|
|
1315
|
+
describe("fragment spreads >> within fragment spreads >>", () => {
|
|
1316
|
+
beforeAll(async () => {
|
|
1317
|
+
analyzeQueryResult = undefined;
|
|
1318
|
+
// @ts-ignore
|
|
1319
|
+
jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
|
|
1320
|
+
|
|
1321
|
+
cacheManager = new CacheManager({
|
|
1322
|
+
cache: new Cachemap({
|
|
1323
|
+
name: "cachemap",
|
|
1324
|
+
store: map(),
|
|
1325
|
+
type: "someType",
|
|
1326
|
+
}),
|
|
1327
|
+
cascadeCacheControl: true,
|
|
1328
|
+
typeIDKey: DEFAULT_TYPE_ID_KEY,
|
|
1329
|
+
});
|
|
1330
|
+
|
|
1331
|
+
const requestData = getRequestData(parsedRequests.getSearchResultsQuery);
|
|
1332
|
+
|
|
1333
|
+
await cacheManager.cacheQuery(
|
|
1334
|
+
requestData,
|
|
1335
|
+
requestData,
|
|
1336
|
+
responses.getSearchResultsQuery,
|
|
1337
|
+
{ awaitDataCaching: true },
|
|
1338
|
+
getRequestContext({ fieldTypeMap: requestFieldTypeMaps.getSearchResultsQuery, hasDeferOrStream: true }),
|
|
1339
|
+
);
|
|
1340
|
+
|
|
1341
|
+
analyzeQueryResult = await cacheManager.analyzeQuery(
|
|
1342
|
+
getRequestData(parsedRequests.getMoviePreviewQuery),
|
|
1343
|
+
{ awaitDataCaching: true },
|
|
1344
|
+
getRequestContext({ fieldTypeMap: requestFieldTypeMaps.getMoviePreviewQuery, hasDeferOrStream: true }),
|
|
1345
|
+
);
|
|
1346
|
+
});
|
|
1347
|
+
|
|
1348
|
+
it("correct request data", () => {
|
|
1349
|
+
const { ast, ...otherProps } = analyzeQueryResult?.updated as RequestData;
|
|
1350
|
+
expect(otherProps).toMatchSnapshot();
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
it("no response data", () => {
|
|
1354
|
+
expect(analyzeQueryResult?.response).toBeUndefined();
|
|
1355
|
+
});
|
|
1356
|
+
|
|
1357
|
+
it("correct cache data", async () => {
|
|
1358
|
+
expect(await cacheManager.cache.export()).toMatchSnapshot();
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
it("correct partial data", () => {
|
|
1362
|
+
// @ts-ignore
|
|
1363
|
+
expect(cacheManager._partialQueryResponses).toMatchSnapshot();
|
|
1364
|
+
});
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1315
1367
|
describe("defer >>", () => {
|
|
1316
1368
|
beforeAll(async () => {
|
|
1317
1369
|
analyzeQueryResult = undefined;
|