@graphql-box/cache-manager 5.3.3 → 5.4.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/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/production.analysis.txt +148 -148
- package/dist/types/cjs/constants.d.cts +5 -5
- package/dist/types/cjs/constants.d.cts.map +1 -1
- package/dist/types/cjs/debug/logCacheEntry.d.cts.map +1 -1
- package/dist/types/cjs/debug/logCacheQuery.d.cts.map +1 -1
- package/dist/types/cjs/debug/logPartialCompiled.d.cts.map +1 -1
- package/dist/types/cjs/helpers/createEntityDataKey.d.cts.map +1 -1
- package/dist/types/cjs/helpers/filterField.d.cts.map +1 -1
- package/dist/types/cjs/helpers/filterFragmentDefinitions.d.cts.map +1 -1
- package/dist/types/cjs/helpers/filterOutPropsWithEntityArgsOrDirectives.d.cts.map +1 -1
- package/dist/types/cjs/helpers/filterOutPropsWithEntityOrArgs.d.cts.map +1 -1
- package/dist/types/cjs/helpers/filterQuery.d.cts.map +1 -1
- package/dist/types/cjs/helpers/getDataValue.d.cts.map +1 -1
- package/dist/types/cjs/helpers/hasTypename.d.cts.map +1 -1
- package/dist/types/cjs/helpers/isFieldEntity.d.cts.map +1 -1
- package/dist/types/cjs/helpers/mergeObjects.d.cts.map +1 -1
- package/dist/types/cjs/helpers/normalizePatchResponseData.d.cts +4 -4
- package/dist/types/cjs/helpers/validTypeIdValue.d.cts.map +1 -1
- package/dist/types/cjs/main.d.cts +6 -6
- package/dist/types/cjs/main.d.cts.map +1 -1
- package/dist/types/cjs/types.d.cts +2 -2
- package/dist/types/esm/constants.d.ts +5 -5
- package/dist/types/esm/constants.d.ts.map +1 -1
- package/dist/types/esm/debug/logCacheEntry.d.ts.map +1 -1
- package/dist/types/esm/debug/logCacheQuery.d.ts.map +1 -1
- package/dist/types/esm/debug/logPartialCompiled.d.ts.map +1 -1
- package/dist/types/esm/helpers/createEntityDataKey.d.ts.map +1 -1
- package/dist/types/esm/helpers/filterField.d.ts.map +1 -1
- package/dist/types/esm/helpers/filterFragmentDefinitions.d.ts.map +1 -1
- package/dist/types/esm/helpers/filterOutPropsWithEntityArgsOrDirectives.d.ts.map +1 -1
- package/dist/types/esm/helpers/filterOutPropsWithEntityOrArgs.d.ts.map +1 -1
- package/dist/types/esm/helpers/filterQuery.d.ts.map +1 -1
- package/dist/types/esm/helpers/getDataValue.d.ts.map +1 -1
- package/dist/types/esm/helpers/hasTypename.d.ts.map +1 -1
- package/dist/types/esm/helpers/isFieldEntity.d.ts.map +1 -1
- package/dist/types/esm/helpers/mergeObjects.d.ts.map +1 -1
- package/dist/types/esm/helpers/normalizePatchResponseData.d.ts +4 -4
- package/dist/types/esm/helpers/validTypeIdValue.d.ts.map +1 -1
- package/dist/types/esm/main.d.ts +6 -6
- package/dist/types/esm/main.d.ts.map +1 -1
- package/dist/types/esm/types.d.ts +2 -2
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +17 -19
- package/src/__snapshots__/index.test.ts.snap +2592 -2592
- package/src/constants.ts +5 -5
- package/src/debug/logCacheEntry.ts +5 -3
- package/src/debug/logCacheQuery.ts +14 -4
- package/src/debug/logPartialCompiled.ts +1 -1
- package/src/helpers/checkFieldPathChecklist.ts +1 -1
- package/src/helpers/createEntityDataKey.ts +3 -1
- package/src/helpers/filterField.ts +3 -3
- package/src/helpers/filterFragmentDefinitions.ts +4 -2
- package/src/helpers/filterFragmentSpreads.ts +3 -3
- package/src/helpers/filterIDsAndTypeNames.ts +4 -4
- package/src/helpers/filterInlineFragments.ts +1 -1
- package/src/helpers/filterOperationAndFragmentDefinitions.ts +2 -2
- package/src/helpers/filterOutPropsWithEntityArgsOrDirectives.ts +4 -1
- package/src/helpers/filterOutPropsWithEntityOrArgs.ts +7 -3
- package/src/helpers/filterQuery.ts +4 -2
- package/src/helpers/getDataValue.ts +4 -0
- package/src/helpers/isFieldEntity.ts +1 -1
- package/src/helpers/isFirstResponseChunk.ts +1 -1
- package/src/helpers/isLastResponseChunk.ts +1 -1
- package/src/helpers/isNotLastResponseChunk.ts +1 -1
- package/src/helpers/isNotResponseChunk.ts +1 -1
- package/src/helpers/mergeObjects.ts +2 -0
- package/src/helpers/mergeResponseDataSets.ts +1 -1
- package/src/helpers/normalizePatchResponseData.ts +1 -1
- package/src/helpers/validTypeIdValue.ts +3 -1
- package/src/index.test.ts +57 -57
- package/src/main.ts +133 -104
- package/src/types.ts +7 -7
package/src/constants.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const METADATA = 'metadata'
|
|
2
|
-
export const CACHE_CONTROL = 'cacheControl'
|
|
3
|
-
export const NO_CACHE = 'noCache'
|
|
1
|
+
export const METADATA = 'metadata';
|
|
2
|
+
export const CACHE_CONTROL = 'cacheControl';
|
|
3
|
+
export const NO_CACHE = 'noCache';
|
|
4
4
|
|
|
5
|
-
export const HEADER_CACHE_CONTROL = 'cache-control'
|
|
6
|
-
export const HEADER_NO_CACHE = 'no-cache'
|
|
5
|
+
export const HEADER_CACHE_CONTROL = 'cache-control';
|
|
6
|
+
export const HEADER_NO_CACHE = 'no-cache';
|
|
@@ -7,7 +7,7 @@ type Descriptor = (
|
|
|
7
7
|
value: unknown,
|
|
8
8
|
cachemapOptions: CachemapOptions,
|
|
9
9
|
options: RequestOptions,
|
|
10
|
-
context: CacheManagerContext & { requestFieldCacheKey?: string }
|
|
10
|
+
context: CacheManagerContext & { requestFieldCacheKey?: string },
|
|
11
11
|
) => Promise<void>;
|
|
12
12
|
|
|
13
13
|
export const logCacheEntry = () => {
|
|
@@ -20,7 +20,7 @@ export const logCacheEntry = () => {
|
|
|
20
20
|
|
|
21
21
|
descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {
|
|
22
22
|
return new Promise<void>(resolve => {
|
|
23
|
-
|
|
23
|
+
const resolver = async () => {
|
|
24
24
|
const { debugManager, requestFieldCacheKey, ...otherContext } = args[5];
|
|
25
25
|
|
|
26
26
|
if (!debugManager) {
|
|
@@ -47,7 +47,9 @@ export const logCacheEntry = () => {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
debugManager.log(CACHE_ENTRY_ADDED, payload);
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
void resolver();
|
|
51
53
|
});
|
|
52
54
|
};
|
|
53
55
|
};
|
|
@@ -5,7 +5,9 @@ type Descriptor = (
|
|
|
5
5
|
cacheType: CacheTypes,
|
|
6
6
|
hash: string,
|
|
7
7
|
options: RequestOptions,
|
|
8
|
-
context: CacheManagerContext & { requestFieldCacheKey?: string }
|
|
8
|
+
context: CacheManagerContext & { requestFieldCacheKey?: string },
|
|
9
|
+
// Proving more difficult to fix, that worth the effort
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
9
11
|
) => Promise<never | undefined>;
|
|
10
12
|
|
|
11
13
|
export const logCacheQuery = () => {
|
|
@@ -17,16 +19,22 @@ export const logCacheQuery = () => {
|
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
// Proving more difficult to fix, that worth the effort
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
24
|
+
return new Promise<never | undefined>(resolve => {
|
|
25
|
+
const resolver = async () => {
|
|
22
26
|
const { debugManager, requestFieldCacheKey, ...otherContext } = args[3];
|
|
23
27
|
|
|
24
28
|
if (!debugManager) {
|
|
29
|
+
// Proving more difficult to fix, that worth the effort
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
25
31
|
resolve(await method.apply(this, args));
|
|
26
32
|
return;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
const startTime = debugManager.now();
|
|
36
|
+
// Proving more difficult to fix, that worth the effort
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
30
38
|
const result = await method.apply(this, args);
|
|
31
39
|
const endTime = debugManager.now();
|
|
32
40
|
const duration = endTime - startTime;
|
|
@@ -43,7 +51,9 @@ export const logCacheQuery = () => {
|
|
|
43
51
|
};
|
|
44
52
|
|
|
45
53
|
debugManager.log(CACHE_ENTRY_QUERIED, payload);
|
|
46
|
-
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
void resolver();
|
|
47
57
|
});
|
|
48
58
|
};
|
|
49
59
|
};
|
|
@@ -2,7 +2,7 @@ import { type CheckFieldPathChecklistResult, type FieldPathChecklistValue } from
|
|
|
2
2
|
|
|
3
3
|
export const checkFieldPathChecklist = (
|
|
4
4
|
fieldPathChecklistValues: FieldPathChecklistValue[] | undefined,
|
|
5
|
-
fieldTypeName: string | undefined
|
|
5
|
+
fieldTypeName: string | undefined,
|
|
6
6
|
): CheckFieldPathChecklistResult => {
|
|
7
7
|
if (!fieldPathChecklistValues || fieldPathChecklistValues.length === 0) {
|
|
8
8
|
return { hasData: false, typeUnused: !!fieldTypeName };
|
|
@@ -4,8 +4,10 @@ import { type CacheManagerContext } from '../types.ts';
|
|
|
4
4
|
export const createEntityDataKey = (
|
|
5
5
|
fieldData: EntityData,
|
|
6
6
|
fieldTypeInfo: FieldTypeInfo,
|
|
7
|
-
context: CacheManagerContext
|
|
7
|
+
context: CacheManagerContext,
|
|
8
8
|
) => {
|
|
9
9
|
const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
|
|
10
|
+
// In context, context.typeIDKey is never gonna be undefined
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
10
12
|
return `${fieldTypeName}::${String(fieldData[context.typeIDKey!])}`;
|
|
11
13
|
};
|
|
@@ -19,7 +19,7 @@ export const filterField = (
|
|
|
19
19
|
fieldPathChecklist: FieldPathChecklist,
|
|
20
20
|
fragmentSpreadChecklist: FragmentSpreadCheckist,
|
|
21
21
|
ancestorRequestFieldPath: string,
|
|
22
|
-
context: CacheManagerContext
|
|
22
|
+
context: CacheManagerContext,
|
|
23
23
|
): boolean => {
|
|
24
24
|
const { fragmentDefinitions, typeIDKey } = context;
|
|
25
25
|
const fieldsAndTypeNames = getChildFields(field, { fragmentDefinitions });
|
|
@@ -43,7 +43,7 @@ export const filterField = (
|
|
|
43
43
|
fragmentSpreadFieldCounter[fragmentName] = {
|
|
44
44
|
hasData: 0,
|
|
45
45
|
total: fragmentDefinitions?.[fragmentName]
|
|
46
|
-
? getChildFields(fragmentDefinitions[fragmentName]
|
|
46
|
+
? (getChildFields(fragmentDefinitions[fragmentName], { fragmentDefinitions })?.length ?? 0)
|
|
47
47
|
: 0,
|
|
48
48
|
};
|
|
49
49
|
}
|
|
@@ -59,7 +59,7 @@ export const filterField = (
|
|
|
59
59
|
{
|
|
60
60
|
requestFieldPath: ancestorRequestFieldPath,
|
|
61
61
|
},
|
|
62
|
-
context
|
|
62
|
+
context,
|
|
63
63
|
);
|
|
64
64
|
|
|
65
65
|
const { hasData, typeUnused } = checkFieldPathChecklist(fieldPathChecklist.get(requestFieldPath), childTypeName);
|
|
@@ -9,7 +9,7 @@ export const filterFragmentDefinitions = (
|
|
|
9
9
|
ast: DocumentNode,
|
|
10
10
|
fieldPathChecklist: FieldPathChecklist,
|
|
11
11
|
fragmentSpreadChecklist: FragmentSpreadCheckist,
|
|
12
|
-
context: CacheManagerContext
|
|
12
|
+
context: CacheManagerContext,
|
|
13
13
|
) => {
|
|
14
14
|
const definitionsToFilter = keys(fragmentSpreadChecklist).reduce<{ name: string; path: string }[]>(
|
|
15
15
|
(namesAndPaths, key) => {
|
|
@@ -20,9 +20,11 @@ export const filterFragmentDefinitions = (
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const { deleted, paths, total } = checklist;
|
|
23
|
+
// Will come back and sort this out later
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
25
|
return deleted === 0 && total === 1 ? [...namesAndPaths, { name: key, path: paths[0]! }] : namesAndPaths;
|
|
24
26
|
},
|
|
25
|
-
[]
|
|
27
|
+
[],
|
|
26
28
|
);
|
|
27
29
|
|
|
28
30
|
const { fragmentDefinitions = {} } = context;
|
|
@@ -8,13 +8,13 @@ export const filterFragmentSpreads = (
|
|
|
8
8
|
field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
|
|
9
9
|
fragmentSpreadFieldCounter: FragmentSpreadFieldCounter,
|
|
10
10
|
fragmentSpreadChecklist: FragmentSpreadCheckist,
|
|
11
|
-
ancestorRequestFieldPath: string
|
|
11
|
+
ancestorRequestFieldPath: string,
|
|
12
12
|
) => {
|
|
13
13
|
if (isEmpty(fragmentSpreadFieldCounter)) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
for (const key of Object.
|
|
17
|
+
for (const [key, value] of Object.entries(fragmentSpreadFieldCounter)) {
|
|
18
18
|
const checklist = fragmentSpreadChecklist[key];
|
|
19
19
|
|
|
20
20
|
if (!checklist) {
|
|
@@ -22,7 +22,7 @@ export const filterFragmentSpreads = (
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
checklist.paths.push(ancestorRequestFieldPath);
|
|
25
|
-
const { hasData, total } =
|
|
25
|
+
const { hasData, total } = value;
|
|
26
26
|
|
|
27
27
|
if (hasData === total) {
|
|
28
28
|
deleteFragmentSpreads(field, key);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TYPE_NAME_KEY } from '@graphql-box/core';
|
|
2
|
-
import { deleteChildFields, getChildFields
|
|
2
|
+
import { deleteChildFields, getChildFields } from '@graphql-box/helpers';
|
|
3
3
|
import { type FieldNode, type FragmentDefinitionNode, type OperationDefinitionNode } from 'graphql';
|
|
4
4
|
import { type CacheManagerContext } from '../types.ts';
|
|
5
5
|
|
|
6
6
|
export const filterIDsAndTypeNames = (
|
|
7
7
|
field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
|
|
8
|
-
{ fragmentDefinitions, typeIDKey }: CacheManagerContext
|
|
8
|
+
{ fragmentDefinitions, typeIDKey }: CacheManagerContext,
|
|
9
9
|
) => {
|
|
10
10
|
const fieldsAndTypeNames = getChildFields(field, { fragmentDefinitions });
|
|
11
11
|
|
|
@@ -13,12 +13,12 @@ export const filterIDsAndTypeNames = (
|
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const fieldNames = fieldsAndTypeNames.map(({ fieldNode }) =>
|
|
16
|
+
const fieldNames = fieldsAndTypeNames.map(({ fieldNode }) => fieldNode.name.value);
|
|
17
17
|
|
|
18
18
|
if (fieldNames.length === 2 && fieldNames.every(name => name === typeIDKey || name === TYPE_NAME_KEY)) {
|
|
19
19
|
deleteChildFields(
|
|
20
20
|
field,
|
|
21
|
-
fieldsAndTypeNames.map(({ fieldNode }) => fieldNode)
|
|
21
|
+
fieldsAndTypeNames.map(({ fieldNode }) => fieldNode),
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
return true;
|
|
@@ -4,7 +4,7 @@ import { type CacheManagerContext } from '../types.ts';
|
|
|
4
4
|
|
|
5
5
|
export const filterInlineFragments = (
|
|
6
6
|
field: FieldNode | FragmentDefinitionNode | OperationDefinitionNode,
|
|
7
|
-
{ fragmentDefinitions, typeIDKey }: CacheManagerContext
|
|
7
|
+
{ fragmentDefinitions, typeIDKey }: CacheManagerContext,
|
|
8
8
|
) => {
|
|
9
9
|
const inlineFragments = getInlineFragments(field);
|
|
10
10
|
let filtered = false;
|
|
@@ -5,6 +5,6 @@ export const filterOperationAndFragmentDefinitions = (ast: DocumentNode) => {
|
|
|
5
5
|
return ast.definitions.filter(
|
|
6
6
|
definition =>
|
|
7
7
|
isKind<OperationDefinitionNode>(definition, Kind.OPERATION_DEFINITION) ||
|
|
8
|
-
isKind<FragmentDefinitionNode>(definition, Kind.FRAGMENT_DEFINITION)
|
|
9
|
-
)
|
|
8
|
+
isKind<FragmentDefinitionNode>(definition, Kind.FRAGMENT_DEFINITION),
|
|
9
|
+
);
|
|
10
10
|
};
|
|
@@ -15,7 +15,7 @@ export const filterOutPropsWithEntityArgsOrDirectives = (
|
|
|
15
15
|
fieldData: unknown,
|
|
16
16
|
field: FieldNode,
|
|
17
17
|
ancestorKeysAndPaths: KeysAndPaths,
|
|
18
|
-
context: CacheManagerContext
|
|
18
|
+
context: CacheManagerContext,
|
|
19
19
|
) => {
|
|
20
20
|
if (!isPlainObject(fieldData)) {
|
|
21
21
|
return fieldData;
|
|
@@ -31,10 +31,13 @@ export const filterOutPropsWithEntityArgsOrDirectives = (
|
|
|
31
31
|
const fieldTypeInfo = context.fieldTypeMap.get(keysAndPaths.requestFieldPath);
|
|
32
32
|
|
|
33
33
|
if (
|
|
34
|
+
// In this context, typeIDKey cannot be undefined
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
34
36
|
isFieldEntity(fieldData[key], fieldTypeInfo, context.typeIDKey!) ||
|
|
35
37
|
fieldTypeInfo?.hasArguments ||
|
|
36
38
|
fieldTypeInfo?.hasDirectives
|
|
37
39
|
) {
|
|
40
|
+
// In this context, this is safe
|
|
38
41
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
39
42
|
delete fieldData[key];
|
|
40
43
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type EntityData } from '@graphql-box/core';
|
|
2
2
|
import { type KeysAndPaths, buildFieldKeysAndPaths, getName, resolveFragments } from '@graphql-box/helpers';
|
|
3
3
|
import { type FieldNode } from 'graphql';
|
|
4
|
-
import { keys } from 'lodash-es';
|
|
5
4
|
import { type CacheManagerContext } from '../types.ts';
|
|
6
5
|
import { isFieldEntity } from './isFieldEntity.ts';
|
|
7
6
|
|
|
@@ -9,18 +8,23 @@ export const filterOutPropsWithEntityOrArgs = (
|
|
|
9
8
|
fieldData: EntityData,
|
|
10
9
|
field: FieldNode,
|
|
11
10
|
ancestorKeysAndPaths: KeysAndPaths,
|
|
12
|
-
context: CacheManagerContext
|
|
11
|
+
context: CacheManagerContext,
|
|
13
12
|
) => {
|
|
14
13
|
const fieldAndTypeName = resolveFragments(field.selectionSet?.selections, context.fragmentDefinitions);
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
// The data returned will be EntityData
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
17
|
+
return Object.keys(fieldData).reduce<Partial<EntityData>>((acc, key) => {
|
|
17
18
|
const match = fieldAndTypeName.find(({ fieldNode }) => getName(fieldNode) === key);
|
|
18
19
|
|
|
19
20
|
if (match) {
|
|
20
21
|
const { requestFieldPath } = buildFieldKeysAndPaths(match.fieldNode, ancestorKeysAndPaths, context);
|
|
21
22
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
22
23
|
|
|
24
|
+
// In this context, typeIDKey will not be undefined
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
26
|
if (isFieldEntity(fieldData[key], fieldTypeInfo, context.typeIDKey!) || fieldTypeInfo?.hasArguments) {
|
|
27
|
+
// In this context, this is safe
|
|
24
28
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
25
29
|
delete fieldData[key];
|
|
26
30
|
}
|
|
@@ -13,7 +13,7 @@ import { filterFragmentDefinitions } from './filterFragmentDefinitions.ts';
|
|
|
13
13
|
export const filterQuery = (
|
|
14
14
|
requestData: RequestData,
|
|
15
15
|
{ fieldPathChecklist }: CachedResponseData,
|
|
16
|
-
context: CacheManagerContext
|
|
16
|
+
context: CacheManagerContext,
|
|
17
17
|
) => {
|
|
18
18
|
const { ast } = requestData;
|
|
19
19
|
const queryNode = getOperationDefinitions(ast, context.operation)[0];
|
|
@@ -32,6 +32,8 @@ export const filterQuery = (
|
|
|
32
32
|
const fragmentSpreadChecklist = createFragmentSpreadChecklist(requestData, context);
|
|
33
33
|
|
|
34
34
|
for (let index = fieldsAndTypeNames.length - 1; index >= 0; index -= 1) {
|
|
35
|
+
// In this context fieldsAndTypeNames[index] will not be undefined
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
37
|
const { fieldNode } = fieldsAndTypeNames[index]!;
|
|
36
38
|
|
|
37
39
|
const { requestFieldPath } = buildFieldKeysAndPaths(
|
|
@@ -39,7 +41,7 @@ export const filterQuery = (
|
|
|
39
41
|
{
|
|
40
42
|
requestFieldPath: operation,
|
|
41
43
|
},
|
|
42
|
-
context
|
|
44
|
+
context,
|
|
43
45
|
);
|
|
44
46
|
|
|
45
47
|
if (filterField(fieldNode, fieldPathChecklist, fragmentSpreadChecklist, requestFieldPath, context)) {
|
|
@@ -3,10 +3,14 @@ import { isNumber, isString } from 'lodash-es';
|
|
|
3
3
|
|
|
4
4
|
export const getDataValue = <T>(value: unknown, key: string | number): T | undefined => {
|
|
5
5
|
if (isArray(value) && isNumber(key)) {
|
|
6
|
+
// Casting for ease of typing for consumers
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
6
8
|
return value[key] as T;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
if (isPlainObject(value) && isString(key)) {
|
|
12
|
+
// Casting for ease of typing for consumers
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
10
14
|
return value[key] as T;
|
|
11
15
|
}
|
|
12
16
|
|
|
@@ -4,7 +4,7 @@ import { isPlainObject } from '@graphql-box/helpers';
|
|
|
4
4
|
export const isFieldEntity = (
|
|
5
5
|
fieldData: unknown,
|
|
6
6
|
fieldTypeInfo: FieldTypeInfo | undefined,
|
|
7
|
-
typeIDKey: string
|
|
7
|
+
typeIDKey: string,
|
|
8
8
|
): fieldData is EntityData => {
|
|
9
9
|
if (!isPlainObject(fieldData) || !(typeIDKey in fieldData)) {
|
|
10
10
|
return false;
|
|
@@ -3,5 +3,5 @@ import { type CacheManagerContext } from '../types.ts';
|
|
|
3
3
|
|
|
4
4
|
export const isFirstResponseChunk = (
|
|
5
5
|
rawResponseData: RawResponseDataWithMaybeCacheMetadata,
|
|
6
|
-
context: CacheManagerContext
|
|
6
|
+
context: CacheManagerContext,
|
|
7
7
|
) => context.hasDeferOrStream && rawResponseData.hasNext && !rawResponseData.paths;
|
|
@@ -3,5 +3,5 @@ import { type CacheManagerContext } from '../types.ts';
|
|
|
3
3
|
|
|
4
4
|
export const isLastResponseChunk = (
|
|
5
5
|
rawResponseData: RawResponseDataWithMaybeCacheMetadata,
|
|
6
|
-
context: CacheManagerContext
|
|
6
|
+
context: CacheManagerContext,
|
|
7
7
|
) => context.hasDeferOrStream && !rawResponseData.hasNext && rawResponseData.paths;
|
|
@@ -3,5 +3,5 @@ import { type CacheManagerContext } from '../types.ts';
|
|
|
3
3
|
|
|
4
4
|
export const isNotLastResponseChunk = (
|
|
5
5
|
rawResponseData: RawResponseDataWithMaybeCacheMetadata,
|
|
6
|
-
context: CacheManagerContext
|
|
6
|
+
context: CacheManagerContext,
|
|
7
7
|
) => context.hasDeferOrStream && rawResponseData.hasNext;
|
|
@@ -3,5 +3,5 @@ import { type CacheManagerContext } from '../types.ts';
|
|
|
3
3
|
|
|
4
4
|
export const isNotResponseChunk = (
|
|
5
5
|
rawResponseData: RawResponseDataWithMaybeCacheMetadata,
|
|
6
|
-
context: CacheManagerContext
|
|
6
|
+
context: CacheManagerContext,
|
|
7
7
|
) => !context.hasDeferOrStream && !rawResponseData.hasNext && !rawResponseData.paths;
|
|
@@ -2,6 +2,8 @@ import { isPlainObject, mergeObjects } from '@graphql-box/helpers';
|
|
|
2
2
|
|
|
3
3
|
export const mergeDataSets = <T extends object>(obj: T, source: T, typeIDKey: string): T => {
|
|
4
4
|
return mergeObjects<T>(obj, source, (_key: string, value: unknown): string | number | undefined => {
|
|
5
|
+
// Casting of ease of typing
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
5
7
|
return isPlainObject(value) && value[typeIDKey] ? (value[typeIDKey] as string | number) : undefined;
|
|
6
8
|
});
|
|
7
9
|
};
|
|
@@ -4,7 +4,7 @@ import { type CacheManagerContext } from '../types.ts';
|
|
|
4
4
|
|
|
5
5
|
export const normalizePatchResponseData = (
|
|
6
6
|
rawResponseData: RawResponseDataWithMaybeCacheMetadata,
|
|
7
|
-
context: CacheManagerContext
|
|
7
|
+
context: CacheManagerContext,
|
|
8
8
|
) => {
|
|
9
9
|
if (!context.normalizePatchResponseData) {
|
|
10
10
|
return rawResponseData;
|
|
@@ -4,13 +4,15 @@ import { isPlainObject } from '@graphql-box/helpers';
|
|
|
4
4
|
export const getValidTypeIdValue = (
|
|
5
5
|
requestFieldPathData: unknown,
|
|
6
6
|
{ typeIDValue }: FieldTypeInfo,
|
|
7
|
-
typeIDKey: string
|
|
7
|
+
typeIDKey: string,
|
|
8
8
|
): string | number | undefined => {
|
|
9
9
|
if (typeIDValue) {
|
|
10
10
|
return typeIDValue;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
if (isPlainObject(requestFieldPathData)) {
|
|
14
|
+
// Identifier value can only be one of these types
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
14
16
|
return requestFieldPathData[typeIDKey] as string | number | undefined;
|
|
15
17
|
}
|
|
16
18
|
|