@apollo/client 4.1.0-alpha.9 → 4.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/__cjs/cache/core/types/Cache.d.cts +3 -2
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +1 -1
- package/__cjs/cache/inmemory/policies.cjs +72 -22
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +31 -9
- package/__cjs/cache/inmemory/readFromStore.cjs +6 -5
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +3 -1
- package/__cjs/cache/inmemory/writeToStore.cjs +18 -4
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +0 -1
- package/__cjs/core/QueryInfo.cjs +6 -1
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +4 -3
- package/__cjs/core/QueryManager.cjs +13 -3
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +2 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +39 -0
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +1 -0
- package/__cjs/incremental/types.d.cts +9 -0
- package/__cjs/react/query-preloader/createQueryPreloader.cjs +41 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/ssr/prerenderStatic.cjs +17 -4
- package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -1
- package/__cjs/react/ssr/prerenderStatic.d.cts +23 -4
- package/__cjs/utilities/internal/constants.cjs +6 -1
- package/__cjs/utilities/internal/constants.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.d.cts +5 -0
- package/__cjs/utilities/internal/index.cjs +2 -1
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +3 -1
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs +61 -0
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.d.cts +11 -0
- package/__cjs/utilities/internal/ponyfills/index.cjs +6 -0
- package/__cjs/utilities/internal/ponyfills/index.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/index.d.cts +3 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.cjs +6 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.d.cts +2 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs +3 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs.map +1 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.d.cts +12 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.cjs +3 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.cjs.map +1 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +16 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.cjs.map +1 -1
- package/cache/core/types/Cache.d.ts +3 -2
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/policies.d.ts +31 -9
- package/cache/inmemory/policies.js +60 -11
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +6 -5
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +3 -1
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +0 -1
- package/cache/inmemory/writeToStore.js +20 -6
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/QueryInfo.d.ts +4 -3
- package/core/QueryInfo.js +7 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +2 -1
- package/core/QueryManager.js +14 -4
- package/core/QueryManager.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +1 -0
- package/incremental/handlers/graphql17Alpha9.js +40 -1
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/types.d.ts +9 -0
- package/incremental/types.js.map +1 -1
- package/legacyEntryPoints/utilities/internal/ponyfills/index.d.ts +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/index.js +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.cjs +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.d.cts +1 -0
- package/package.json +15 -1
- package/react/query-preloader/createQueryPreloader.js +41 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/ssr/prerenderStatic.d.ts +24 -5
- package/react/ssr/prerenderStatic.js +17 -4
- package/react/ssr/prerenderStatic.js.map +1 -1
- package/utilities/internal/constants.d.ts +5 -0
- package/utilities/internal/constants.js +5 -0
- package/utilities/internal/constants.js.map +1 -1
- package/utilities/internal/index.d.ts +3 -1
- package/utilities/internal/index.js +1 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/ponyfills/FinalizationRegistry.d.ts +11 -0
- package/utilities/internal/ponyfills/FinalizationRegistry.js +57 -0
- package/utilities/internal/ponyfills/FinalizationRegistry.js.map +1 -0
- package/utilities/internal/ponyfills/index.d.ts +3 -0
- package/utilities/internal/ponyfills/index.js +3 -0
- package/utilities/internal/ponyfills/index.js.map +1 -0
- package/utilities/internal/ponyfills/index.react-native.d.ts +2 -0
- package/utilities/internal/ponyfills/index.react-native.js +2 -0
- package/utilities/internal/ponyfills/index.react-native.js.map +1 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.d.ts +12 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.js +2 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.js.map +1 -0
- package/utilities/internal/types/StreamInfoTrie.d.ts +16 -0
- package/utilities/internal/types/StreamInfoTrie.js +2 -0
- package/utilities/internal/types/StreamInfoTrie.js.map +1 -0
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FinalizationRegistry = void 0;
|
|
4
|
+
const invariant_1 = require("@apollo/client/utilities/invariant");
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* An approximation of `FinalizationRegistry` based on `WeakRef`.
|
|
9
|
+
* While there are registered values, checks every 500ms if any have been garbage collected.
|
|
10
|
+
* The polling interval is cleared once all registered entries have been removed.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
13
|
+
*/
|
|
14
|
+
const FinalizationRegistry = class FinalizationRegistry {
|
|
15
|
+
intervalLength = 500;
|
|
16
|
+
callback;
|
|
17
|
+
references = new Set();
|
|
18
|
+
unregisterTokens = new WeakMap();
|
|
19
|
+
interval = null;
|
|
20
|
+
constructor(callback) {
|
|
21
|
+
this.callback = callback;
|
|
22
|
+
this.handler = this.handler.bind(this);
|
|
23
|
+
}
|
|
24
|
+
handler() {
|
|
25
|
+
if (this.references.size === 0) {
|
|
26
|
+
clearInterval(this.interval);
|
|
27
|
+
this.interval = null;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.references.forEach((entry) => {
|
|
31
|
+
if (entry.targetRef.deref() === undefined) {
|
|
32
|
+
this.references.delete(entry);
|
|
33
|
+
// Spec deviation: Not catching errors here, might get necessary if used in more places.
|
|
34
|
+
this.callback(entry.value);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
register(target, value, unregisterToken) {
|
|
39
|
+
const entry = { targetRef: new WeakRef(target), value };
|
|
40
|
+
this.references.add(entry);
|
|
41
|
+
if (unregisterToken) {
|
|
42
|
+
// some simplifications here as it's an internal polyfill
|
|
43
|
+
// we don't allow the same unregisterToken to be reused
|
|
44
|
+
(0, invariant_1.invariant)(!this.unregisterTokens.has(unregisterToken));
|
|
45
|
+
this.unregisterTokens.set(unregisterToken, entry);
|
|
46
|
+
}
|
|
47
|
+
if (!this.interval) {
|
|
48
|
+
this.interval = setInterval(this.handler, this.intervalLength);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
unregister(unregisterToken) {
|
|
52
|
+
// Calling `(weak)Set.delete(undefined)` is not covered by the TypeScript types,
|
|
53
|
+
// but valid by the spec (see https://tc39.es/ecma262/multipage/keyed-collections.html#sec-weakset.prototype.delete).
|
|
54
|
+
// Shaving a few bytes here by skipping the undefined check.
|
|
55
|
+
this.references.delete(this.unregisterTokens.get(unregisterToken));
|
|
56
|
+
return this.unregisterTokens.delete(unregisterToken);
|
|
57
|
+
}
|
|
58
|
+
[Symbol.toStringTag] = "FinalizationRegistry";
|
|
59
|
+
};
|
|
60
|
+
exports.FinalizationRegistry = FinalizationRegistry;
|
|
61
|
+
//# sourceMappingURL=FinalizationRegistry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FinalizationRegistry.cjs","sources":["../../../../../src/utilities/internal/ponyfills/FinalizationRegistry.ts"],"sourcesContent":["import { invariant } from \"@apollo/client/utilities/invariant\";\n\ninterface Entry<T> {\n targetRef: WeakRef<WeakKey>;\n value: T;\n}\n\n/**\n * @internal\n *\n * An approximation of `FinalizationRegistry` based on `WeakRef`.\n * While there are registered values, checks every 500ms if any have been garbage collected.\n * The polling interval is cleared once all registered entries have been removed.\n */\nexport const FinalizationRegistry: typeof globalThis.FinalizationRegistry = class FinalizationRegistry<\n T,\n> {\n private intervalLength = 500;\n private callback: (value: T) => void;\n private references = new Set<Entry<T>>();\n private unregisterTokens = new WeakMap<WeakKey, Entry<T>>();\n private interval: ReturnType<typeof setInterval> | null = null;\n constructor(callback: (value: T) => void) {\n this.callback = callback;\n this.handler = this.handler.bind(this);\n }\n handler() {\n if (this.references.size === 0) {\n clearInterval(this.interval!);\n this.interval = null;\n return;\n }\n this.references.forEach((entry) => {\n if (entry.targetRef.deref() === undefined) {\n this.references.delete(entry);\n // Spec deviation: Not catching errors here, might get necessary if used in more places.\n this.callback(entry.value);\n }\n });\n }\n register(target: WeakKey, value: T, unregisterToken?: WeakKey): void {\n const entry = { targetRef: new WeakRef(target), value };\n this.references.add(entry);\n if (unregisterToken) {\n // some simplifications here as it's an internal polyfill\n // we don't allow the same unregisterToken to be reused\n invariant(!this.unregisterTokens.has(unregisterToken));\n this.unregisterTokens.set(unregisterToken, entry);\n }\n if (!this.interval) {\n this.interval = setInterval(this.handler, this.intervalLength);\n }\n }\n unregister(unregisterToken: WeakKey): boolean {\n // Calling `(weak)Set.delete(undefined)` is not covered by the TypeScript types,\n // but valid by the spec (see https://tc39.es/ecma262/multipage/keyed-collections.html#sec-weakset.prototype.delete).\n // Shaving a few bytes here by skipping the undefined check.\n this.references.delete(this.unregisterTokens.get(unregisterToken)!);\n return this.unregisterTokens.delete(unregisterToken);\n }\n [Symbol.toStringTag] = \"FinalizationRegistry\" as const;\n};\n"],"names":[],"mappings":";;;AAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;AAcO,CAAP,CAAA,CAAA,CAAA,EAAa,CAAb,CAAA,CAAA,CAAA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CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*
|
|
4
|
+
* An approximation of `FinalizationRegistry` based on `WeakRef`.
|
|
5
|
+
* While there are registered values, checks every 500ms if any have been garbage collected.
|
|
6
|
+
* The polling interval is cleared once all registered entries have been removed.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
9
|
+
*/
|
|
10
|
+
export declare const FinalizationRegistry: typeof globalThis.FinalizationRegistry;
|
|
11
|
+
//# sourceMappingURL=FinalizationRegistry.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../src/utilities/internal/ponyfills/index.ts"],"sourcesContent":["const F = FinalizationRegistry;\nexport { F as FinalizationRegistry };\n"],"names":[],"mappings":";;;AAAA,CAAA,CAAA,CAAA,CAAA,EAAM,EAAN,EAAU,CAAV,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA8B;AAChB,CAAd,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FinalizationRegistry = void 0;
|
|
4
|
+
var FinalizationRegistry_js_1 = require("./FinalizationRegistry.cjs");
|
|
5
|
+
Object.defineProperty(exports, "FinalizationRegistry", { enumerable: true, get: function () { return FinalizationRegistry_js_1.FinalizationRegistry; } });
|
|
6
|
+
//# sourceMappingURL=index.react-native.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.react-native.cjs","sources":["../../../../../src/utilities/internal/ponyfills/index.react-native.ts"],"sourcesContent":["export { FinalizationRegistry } from \"./FinalizationRegistry.js\";\n"],"names":[],"mappings":";;;AAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,6BAAA,CAAA;AAAS,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA6B,EAA7B,EAAA,CAAA,CAAA;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionsWithStreamDetails.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { streamInfoSymbol } from "../constants.cjs";
|
|
2
|
+
import type { StreamInfoTrie } from "./StreamInfoTrie.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* For use in Cache implementations only.
|
|
5
|
+
* This should not be used in userland code.
|
|
6
|
+
*/
|
|
7
|
+
export interface ExtensionsWithStreamInfo extends Record<string, unknown> {
|
|
8
|
+
[streamInfoSymbol]?: {
|
|
9
|
+
deref(): StreamInfoTrie | undefined;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ExtensionsWithStreamDetails.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamInfoTrie.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Trie } from "@wry/trie";
|
|
2
|
+
import type { Incremental } from "@apollo/client/incremental";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
7
|
+
*/
|
|
8
|
+
export type StreamInfoTrie = Trie<{
|
|
9
|
+
current: Incremental.StreamFieldInfo;
|
|
10
|
+
previous?: {
|
|
11
|
+
incoming: unknown;
|
|
12
|
+
streamFieldInfo: Incremental.StreamFieldInfo;
|
|
13
|
+
result: unknown;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=StreamInfoTrie.d.cts.map
|
package/__cjs/version.cjs
CHANGED
package/__cjs/version.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,
|
|
1
|
+
{"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,cAAwC;AAC3B,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,EAAA,OAAyD;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DataValue, DocumentNode, OperationVariables, TypedDocumentNode } from "@apollo/client";
|
|
2
2
|
import type { Unmasked } from "@apollo/client/masking";
|
|
3
|
+
import type { ExtensionsWithStreamInfo } from "@apollo/client/utilities/internal";
|
|
3
4
|
import type { ApolloCache } from "../cache.js";
|
|
4
5
|
import type { AllFieldsModifier, MissingFieldError, Modifiers } from "./common.js";
|
|
5
6
|
export declare namespace Cache {
|
|
@@ -54,7 +55,7 @@ export declare namespace Cache {
|
|
|
54
55
|
* GraphQL extensions for the write operation. Any provided `extensions`
|
|
55
56
|
* are available in `merge` functions.
|
|
56
57
|
*/
|
|
57
|
-
extensions?:
|
|
58
|
+
extensions?: ExtensionsWithStreamInfo;
|
|
58
59
|
}
|
|
59
60
|
interface DiffOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends Omit<ReadOptions<TData, TVariables>, "rootId"> {
|
|
60
61
|
}
|
|
@@ -211,7 +212,7 @@ export declare namespace Cache {
|
|
|
211
212
|
* GraphQL extensions for the write operation. Any provided `extensions`
|
|
212
213
|
* are available in `merge` functions.
|
|
213
214
|
*/
|
|
214
|
-
extensions?:
|
|
215
|
+
extensions?: ExtensionsWithStreamInfo;
|
|
215
216
|
}
|
|
216
217
|
type WriteFragmentOptions<TData, TVariables extends OperationVariables> = {
|
|
217
218
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\n\nimport type { ApolloCache } from \"../cache.js\";\n\nimport type {\n AllFieldsModifier,\n MissingFieldError,\n Modifiers,\n} from \"./common.js\";\nexport declare namespace Cache {\n export type WatchCallback<TData = unknown> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export interface ReadOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n }\n\n export interface WriteOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n dataId?: string;\n result: Unmasked<TData>;\n\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: Record<string, unknown>;\n }\n\n export interface DiffOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Omit<ReadOptions<TData, TVariables>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends ApolloCache,\n TUpdateResult = void,\n > {\n /**\n * A function that performs cache operations. Receives the cache instance as its argument.\n *\n * The return value of this function becomes the return value of `batch`.\n */\n update(cache: TCache): TUpdateResult;\n\n /**\n * Controls how optimistic data is handled:\n *\n * - `string`: Creates a new optimistic layer with this ID. Use `removeOptimistic` later to remove it.\n * - `true`: Updates the current top layer of the cache (including any optimistic data).\n * - `false`: Updates only the root (non-optimistic) cache data.\n *\n * @defaultValue false\n */\n optimistic?: string | boolean;\n\n /**\n * If provided, removes the optimistic layer with this ID after the batch completes.\n *\n * This is useful for atomically applying server data while removing a pending optimistic update, triggering at most one broadcast for both operations.\n *\n * Note: this option is needed because calling `cache.removeOptimistic` during the transaction function may not be safe, since any modifications to cache layers may be discarded after the transaction finishes.\n */\n removeOptimistic?: string;\n\n /**\n * Optional callback invoked for each watcher affected by the batch operation.\n *\n * Receives the watch options, the new diff result, and optionally the previous diff result.\n *\n * Return `false` to prevent broadcasting to that specific watcher.\n */\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export interface ReadQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes readQuery capable of reading data\n * from any object in the cache.\n */\n id?: string;\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n }\n\n export type ReadFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readFragment method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface WriteQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: Record<string, unknown>;\n }\n\n export type WriteFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string\n * with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface UpdateQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > extends Omit<\n ReadQueryOptions<TData, TVariables> &\n WriteQueryOptions<TData, TVariables>,\n \"data\"\n > {}\n\n export type UpdateFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = Omit<\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>,\n \"data\" | \"id\" | \"from\"\n > &\n Cache.CacheIdentifierOption<TData>;\n\n export type DiffResult<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData> | null;\n complete: false;\n missing?: MissingFieldError;\n fromOptimisticTransaction?: boolean;\n };\n\n export type CacheIdentifierOption<TData> =\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: never;\n }\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: never;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: ApolloCache.FromOptionValue<TData>;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\nimport type { ExtensionsWithStreamInfo } from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache } from \"../cache.js\";\n\nimport type {\n AllFieldsModifier,\n MissingFieldError,\n Modifiers,\n} from \"./common.js\";\nexport declare namespace Cache {\n export type WatchCallback<TData = unknown> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export interface ReadOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n }\n\n export interface WriteOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n dataId?: string;\n result: Unmasked<TData>;\n\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export interface DiffOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Omit<ReadOptions<TData, TVariables>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends ApolloCache,\n TUpdateResult = void,\n > {\n /**\n * A function that performs cache operations. Receives the cache instance as its argument.\n *\n * The return value of this function becomes the return value of `batch`.\n */\n update(cache: TCache): TUpdateResult;\n\n /**\n * Controls how optimistic data is handled:\n *\n * - `string`: Creates a new optimistic layer with this ID. Use `removeOptimistic` later to remove it.\n * - `true`: Updates the current top layer of the cache (including any optimistic data).\n * - `false`: Updates only the root (non-optimistic) cache data.\n *\n * @defaultValue false\n */\n optimistic?: string | boolean;\n\n /**\n * If provided, removes the optimistic layer with this ID after the batch completes.\n *\n * This is useful for atomically applying server data while removing a pending optimistic update, triggering at most one broadcast for both operations.\n *\n * Note: this option is needed because calling `cache.removeOptimistic` during the transaction function may not be safe, since any modifications to cache layers may be discarded after the transaction finishes.\n */\n removeOptimistic?: string;\n\n /**\n * Optional callback invoked for each watcher affected by the batch operation.\n *\n * Receives the watch options, the new diff result, and optionally the previous diff result.\n *\n * Return `false` to prevent broadcasting to that specific watcher.\n */\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export interface ReadQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes readQuery capable of reading data\n * from any object in the cache.\n */\n id?: string;\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n }\n\n export type ReadFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readFragment method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface WriteQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export type WriteFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string\n * with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface UpdateQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > extends Omit<\n ReadQueryOptions<TData, TVariables> &\n WriteQueryOptions<TData, TVariables>,\n \"data\"\n > {}\n\n export type UpdateFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = Omit<\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>,\n \"data\" | \"id\" | \"from\"\n > &\n Cache.CacheIdentifierOption<TData>;\n\n export type DiffResult<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData> | null;\n complete: false;\n missing?: MissingFieldError;\n fromOptimisticTransaction?: boolean;\n };\n\n export type CacheIdentifierOption<TData> =\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: never;\n }\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: never;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: ApolloCache.FromOptionValue<TData>;\n };\n}\n"]}
|
package/cache/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { defaultDataIdFromObject, fieldNameFromStoreName, } from "./inmemory/hel
|
|
|
11
11
|
export { InMemoryCache } from "./inmemory/inMemoryCache.js";
|
|
12
12
|
export type { ReactiveVar } from "./inmemory/reactiveVars.js";
|
|
13
13
|
export { cacheSlot, makeVar } from "./inmemory/reactiveVars.js";
|
|
14
|
-
export type { FieldFunctionOptions, FieldMergeFunction, FieldPolicy, FieldReadFunction, PossibleTypesMap, TypePolicies, TypePolicy, } from "./inmemory/policies.js";
|
|
14
|
+
export type { FieldFunctionOptions, FieldMergeFunction, FieldMergeFunctionOptions, FieldPolicy, FieldReadFunction, FieldReadFunctionOptions, PossibleTypesMap, TypePolicies, TypePolicy, } from "./inmemory/policies.js";
|
|
15
15
|
export { Policies } from "./inmemory/policies.js";
|
|
16
16
|
export type { FragmentRegistryAPI } from "./inmemory/fragmentRegistry.js";
|
|
17
17
|
export { createFragmentRegistry } from "./inmemory/fragmentRegistry.js";
|
package/cache/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAU9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAU9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAahE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export type { Transaction } from \"./core/cache.js\";\nexport type {\n WatchFragmentOptions,\n WatchFragmentResult,\n} from \"./deprecated.js\";\nexport { ApolloCache } from \"./core/cache.js\";\nexport type { Cache } from \"./core/types/Cache.js\";\nexport type {\n IgnoreModifier,\n MissingTree,\n Modifier,\n ModifierDetails,\n Modifiers,\n ReadFieldOptions,\n} from \"./core/types/common.js\";\nexport { MissingFieldError } from \"./core/types/common.js\";\n\nexport type { Reference } from \"@apollo/client/utilities\";\nexport { canonicalStringify, isReference } from \"@apollo/client/utilities\";\n\nexport { EntityStore } from \"./inmemory/entityStore.js\";\nexport {\n defaultDataIdFromObject,\n fieldNameFromStoreName,\n} from \"./inmemory/helpers.js\";\n\nexport { InMemoryCache } from \"./inmemory/inMemoryCache.js\";\n\nexport type { ReactiveVar } from \"./inmemory/reactiveVars.js\";\nexport { cacheSlot, makeVar } from \"./inmemory/reactiveVars.js\";\n\nexport type {\n FieldFunctionOptions,\n FieldMergeFunction,\n FieldMergeFunctionOptions,\n FieldPolicy,\n FieldReadFunction,\n FieldReadFunctionOptions,\n PossibleTypesMap,\n TypePolicies,\n TypePolicy,\n} from \"./inmemory/policies.js\";\nexport { Policies } from \"./inmemory/policies.js\";\n\nexport type { FragmentRegistryAPI } from \"./inmemory/fragmentRegistry.js\";\nexport { createFragmentRegistry } from \"./inmemory/fragmentRegistry.js\";\n\nexport type {\n ApolloReducerConfig,\n DiffQueryAgainstStoreOptions,\n IdGetter,\n IdGetterObj,\n InMemoryCacheConfig,\n MergeInfo,\n MergeTree,\n NormalizedCache,\n NormalizedCacheObject,\n OptimisticStoreItem,\n ReadMergeModifyContext,\n ReadQueryOptions,\n StoreObject,\n StoreValue,\n} from \"./inmemory/types.js\";\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FieldNode, FragmentDefinitionNode, InlineFragmentNode, SelectionSetNode } from "graphql";
|
|
2
2
|
import type { OperationVariables } from "@apollo/client";
|
|
3
|
+
import type { Incremental } from "@apollo/client/incremental";
|
|
3
4
|
import type { Reference, StoreObject, StoreValue } from "@apollo/client/utilities";
|
|
4
5
|
import { isReference } from "@apollo/client/utilities";
|
|
5
6
|
import type { FragmentMap } from "@apollo/client/utilities/internal";
|
|
@@ -36,10 +37,10 @@ export type KeyArgsFunction = (args: Record<string, any> | null, context: {
|
|
|
36
37
|
field: FieldNode | null;
|
|
37
38
|
variables?: Record<string, any>;
|
|
38
39
|
}) => KeySpecifier | false | ReturnType<IdGetter>;
|
|
39
|
-
export type FieldPolicy<TExisting = any, TIncoming = TExisting, TReadResult = TIncoming,
|
|
40
|
+
export type FieldPolicy<TExisting = any, TIncoming = TExisting, TReadResult = TIncoming, TReadOptions extends FieldReadFunctionOptions = FieldReadFunctionOptions, TMergeOptions extends FieldMergeFunctionOptions = FieldMergeFunctionOptions> = {
|
|
40
41
|
keyArgs?: KeySpecifier | KeyArgsFunction | false;
|
|
41
|
-
read?: FieldReadFunction<TExisting, TReadResult,
|
|
42
|
-
merge?: FieldMergeFunction<TExisting, TIncoming,
|
|
42
|
+
read?: FieldReadFunction<TExisting, TReadResult, TReadOptions>;
|
|
43
|
+
merge?: FieldMergeFunction<TExisting, TIncoming, TMergeOptions> | boolean;
|
|
43
44
|
};
|
|
44
45
|
export type StorageType = Record<string, any>;
|
|
45
46
|
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> {
|
|
@@ -55,15 +56,36 @@ export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables ex
|
|
|
55
56
|
readField: ReadFieldFunction;
|
|
56
57
|
canRead: CanReadFunction;
|
|
57
58
|
mergeObjects: MergeObjectsFunction;
|
|
59
|
+
}
|
|
60
|
+
export interface FieldReadFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> extends FieldFunctionOptions<TArgs, TVariables> {
|
|
61
|
+
}
|
|
62
|
+
export interface FieldMergeFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> extends FieldFunctionOptions<TArgs, TVariables> {
|
|
63
|
+
/**
|
|
64
|
+
* Any `extensions` provided when writing the cache.
|
|
65
|
+
*/
|
|
66
|
+
extensions: Record<string, unknown> | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Details about the field when the `@stream` directive is used. Useful with
|
|
69
|
+
* custom merge functions to determine how to merge existing cache data with
|
|
70
|
+
* the incoming stream array.
|
|
71
|
+
*
|
|
72
|
+
* This field is only available in `merge` functions when the `@stream`
|
|
73
|
+
* directive is used on the field.
|
|
74
|
+
*
|
|
75
|
+
* > [!NOTE]
|
|
76
|
+
* > This field is not available when using the `Defer20220824Handler`
|
|
77
|
+
*/
|
|
78
|
+
streamFieldInfo?: Incremental.StreamFieldInfo;
|
|
58
79
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
80
|
+
* The same value as the `existing` argument, but preserves the `existing`
|
|
81
|
+
* value on refetches when `refetchWritePolicy` is `overwrite` (the default).
|
|
61
82
|
*/
|
|
62
|
-
|
|
83
|
+
existingData: unknown;
|
|
63
84
|
}
|
|
64
85
|
type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;
|
|
65
|
-
export type FieldReadFunction<TExisting = any, TReadResult = TExisting, TOptions extends
|
|
66
|
-
export type FieldMergeFunction<TExisting = any, TIncoming = TExisting, TOptions extends
|
|
86
|
+
export type FieldReadFunction<TExisting = any, TReadResult = TExisting, TOptions extends FieldReadFunctionOptions = FieldReadFunctionOptions> = (existing: SafeReadonly<TExisting> | undefined, options: TOptions) => TReadResult | undefined;
|
|
87
|
+
export type FieldMergeFunction<TExisting = any, TIncoming = TExisting, TOptions extends FieldMergeFunctionOptions = FieldMergeFunctionOptions> = (existing: SafeReadonly<TExisting> | undefined, incoming: SafeReadonly<TIncoming>, options: TOptions) => SafeReadonly<TExisting>;
|
|
88
|
+
export declare const defaultStreamFieldMergeFn: FieldMergeFunction<Array<any>>;
|
|
67
89
|
export type PossibleTypesMap = {
|
|
68
90
|
[supertype: string]: string[];
|
|
69
91
|
};
|
|
@@ -97,7 +119,7 @@ export declare class Policies {
|
|
|
97
119
|
readField<V = StoreValue>(options: ReadFieldOptions, context: ReadMergeModifyContext): SafeReadonly<V> | undefined;
|
|
98
120
|
getReadFunction(typename: string | undefined, fieldName: string): FieldReadFunction | undefined;
|
|
99
121
|
getMergeFunction(parentTypename: string | undefined, fieldName: string, childTypename: string | undefined): FieldMergeFunction | undefined;
|
|
100
|
-
runMergeFunction(existing: StoreValue, incoming: StoreValue, { field, typename, merge }: MergeInfo, context: WriteContext, storage?: StorageType): any;
|
|
122
|
+
runMergeFunction(existing: StoreValue, incoming: StoreValue, { field, typename, merge, path }: MergeInfo, context: WriteContext, storage?: StorageType): any;
|
|
101
123
|
}
|
|
102
124
|
export declare function normalizeReadFieldOptions(readFieldArgs: any[], objectOrReference: StoreObject | Reference | undefined, variables?: ReadMergeModifyContext["variables"]): ReadFieldOptions;
|
|
103
125
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { equal } from "@wry/equality";
|
|
1
2
|
import { disableWarningsSlot } from "@apollo/client/masking";
|
|
2
3
|
import { isReference } from "@apollo/client/utilities";
|
|
3
4
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
5
|
+
import { streamInfoSymbol } from "@apollo/client/utilities/internal";
|
|
4
6
|
import { argumentsObjectFromField, getStoreKeyName, isArray, isNonNullObject, storeKeyNameFromField, stringifyForDisplay, } from "@apollo/client/utilities/internal";
|
|
5
7
|
import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
|
|
6
8
|
import { defaultDataIdFromObject, fieldNameFromStoreName, hasOwn, selectionSetMatchesResult, storeValueIsStoreObject, TypeOrFieldNameRegExp, } from "./helpers.js";
|
|
@@ -17,6 +19,20 @@ const simpleKeyArgsFn = (_args, context) => context.fieldName;
|
|
|
17
19
|
// merge:false in a field policy.
|
|
18
20
|
const mergeTrueFn = (existing, incoming, { mergeObjects }) => mergeObjects(existing, incoming);
|
|
19
21
|
const mergeFalseFn = (_, incoming) => incoming;
|
|
22
|
+
export const defaultStreamFieldMergeFn = (existing, incoming, { streamFieldInfo, existingData }) => {
|
|
23
|
+
if (!existing && !existingData) {
|
|
24
|
+
return incoming;
|
|
25
|
+
}
|
|
26
|
+
const results = [];
|
|
27
|
+
const previous = existing ?? existingData;
|
|
28
|
+
const length = streamFieldInfo?.isLastChunk ?
|
|
29
|
+
incoming.length
|
|
30
|
+
: Math.max(previous.length, incoming.length);
|
|
31
|
+
for (let i = 0; i < length; i++) {
|
|
32
|
+
results[i] = incoming[i] === undefined ? previous[i] : incoming[i];
|
|
33
|
+
}
|
|
34
|
+
return results;
|
|
35
|
+
};
|
|
20
36
|
export class Policies {
|
|
21
37
|
config;
|
|
22
38
|
typePolicies = {};
|
|
@@ -476,7 +492,9 @@ export class Policies {
|
|
|
476
492
|
}
|
|
477
493
|
return merge;
|
|
478
494
|
}
|
|
479
|
-
runMergeFunction(existing, incoming, { field, typename, merge }, context, storage) {
|
|
495
|
+
runMergeFunction(existing, incoming, { field, typename, merge, path }, context, storage) {
|
|
496
|
+
// Preserve the value in case `context.overwrite` is set.
|
|
497
|
+
const existingData = existing;
|
|
480
498
|
if (merge === mergeTrueFn) {
|
|
481
499
|
// Instead of going to the trouble of creating a full
|
|
482
500
|
// FieldFunctionOptions object and calling mergeTrueFn, we can
|
|
@@ -494,7 +512,18 @@ export class Policies {
|
|
|
494
512
|
if (context.overwrite) {
|
|
495
513
|
existing = void 0;
|
|
496
514
|
}
|
|
497
|
-
|
|
515
|
+
const streamInfo = context.extensions?.[streamInfoSymbol]
|
|
516
|
+
?.deref()
|
|
517
|
+
?.peekArray(path);
|
|
518
|
+
if (streamInfo) {
|
|
519
|
+
const { current, previous } = streamInfo;
|
|
520
|
+
if (previous &&
|
|
521
|
+
equal(previous.incoming, incoming) &&
|
|
522
|
+
equal(previous.streamFieldInfo, current)) {
|
|
523
|
+
return previous.result;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
const result = merge(existing, incoming, makeMergeFieldFunctionOptions(this,
|
|
498
527
|
// Unlike options.readField for read functions, we do not fall
|
|
499
528
|
// back to the current object if no foreignObjOrRef is provided,
|
|
500
529
|
// because it's not clear what the current object should be for
|
|
@@ -511,7 +540,16 @@ export class Policies {
|
|
|
511
540
|
fieldName: field.name.value,
|
|
512
541
|
field,
|
|
513
542
|
variables: context.variables,
|
|
514
|
-
|
|
543
|
+
path,
|
|
544
|
+
}, context, storage || {}, existingData));
|
|
545
|
+
if (streamInfo) {
|
|
546
|
+
streamInfo.previous = {
|
|
547
|
+
incoming,
|
|
548
|
+
streamFieldInfo: streamInfo.current,
|
|
549
|
+
result,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return result;
|
|
515
553
|
}
|
|
516
554
|
}
|
|
517
555
|
function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, context, storage) {
|
|
@@ -519,7 +557,7 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
519
557
|
const fieldName = fieldNameFromStoreName(storeFieldName);
|
|
520
558
|
const variables = fieldSpec.variables || context.variables;
|
|
521
559
|
const { toReference, canRead } = context.store;
|
|
522
|
-
|
|
560
|
+
return {
|
|
523
561
|
args: argsFromFieldSpecifier(fieldSpec),
|
|
524
562
|
field: fieldSpec.field || null,
|
|
525
563
|
fieldName,
|
|
@@ -535,13 +573,24 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
535
573
|
},
|
|
536
574
|
mergeObjects: makeMergeObjectsFunction(context.store),
|
|
537
575
|
};
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
576
|
+
}
|
|
577
|
+
function makeMergeFieldFunctionOptions(policies, objectOrReference, fieldSpec, context, storage, existingData) {
|
|
578
|
+
const options = {
|
|
579
|
+
...makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, context, storage),
|
|
580
|
+
extensions: context.extensions,
|
|
581
|
+
existingData,
|
|
582
|
+
};
|
|
583
|
+
const extensions = context.extensions;
|
|
584
|
+
if (extensions && streamInfoSymbol in extensions) {
|
|
585
|
+
const { [streamInfoSymbol]: streamInfo, ...otherExtensions } = extensions;
|
|
586
|
+
const streamFieldInfo = streamInfo?.deref()?.peekArray(fieldSpec.path);
|
|
587
|
+
if (streamFieldInfo) {
|
|
588
|
+
options.streamFieldInfo = streamFieldInfo.current;
|
|
589
|
+
}
|
|
590
|
+
// If the only key in `extensions` was the stream details key, we didn't
|
|
591
|
+
// receive any remote extensions, so we reset extensions back to undefined
|
|
592
|
+
options.extensions =
|
|
593
|
+
Object.keys(otherExtensions).length === 0 ? undefined : otherExtensions;
|
|
545
594
|
}
|
|
546
595
|
return options;
|
|
547
596
|
}
|