@apollo/client 4.3.0-alpha.6 → 4.3.0-alpha.7
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 +12 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +5 -5
- package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ObservableQuery.cjs +166 -54
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +3 -6
- package/__cjs/core/QueryInfo.cjs +11 -125
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +0 -24
- package/__cjs/core/QueryManager.cjs +12 -14
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/invariantErrorCodes.cjs +52 -32
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.js +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +5 -5
- package/cache/inmemory/readFromStore.js +3 -3
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ObservableQuery.d.ts +3 -6
- package/core/ObservableQuery.js +162 -54
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +1 -25
- package/core/QueryInfo.js +11 -125
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +12 -14
- package/core/QueryManager.js.map +1 -1
- package/core/RefetchEventManager.js +3 -3
- package/invariantErrorCodes.js +52 -32
- package/package.json +1 -1
- package/version.js +1 -1
|
@@ -278,12 +278,8 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
278
278
|
readonly options: ObservableQuery.Options<TData, TVariables>;
|
|
279
279
|
readonly queryName?: string;
|
|
280
280
|
private variablesUnknown;
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
*
|
|
284
|
-
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
285
|
-
*/
|
|
286
|
-
_lastWrite?: unknown;
|
|
281
|
+
private didWarnOnFeud;
|
|
282
|
+
private lastMissing?;
|
|
287
283
|
get query(): TypedDocumentNode<TData, TVariables>;
|
|
288
284
|
/**
|
|
289
285
|
* An object containing the variables that were provided for the query.
|
|
@@ -469,6 +465,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
469
465
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
470
466
|
*/
|
|
471
467
|
notify(scheduled?: boolean): void;
|
|
468
|
+
private deliverCacheDiff;
|
|
472
469
|
private activeOperations;
|
|
473
470
|
private pushOperation;
|
|
474
471
|
private calculateNetworkStatus;
|
package/__cjs/core/QueryInfo.cjs
CHANGED
|
@@ -5,30 +5,12 @@ const {
|
|
|
5
5
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.QueryInfo = void 0;
|
|
8
|
-
const equality_1 = require("@wry/equality");
|
|
9
8
|
const trie_1 = require("@wry/trie");
|
|
10
9
|
const environment_1 = require("@apollo/client/utilities/environment");
|
|
11
10
|
const internal_1 = require("@apollo/client/utilities/internal");
|
|
12
11
|
const invariant_1 = require("@apollo/client/utilities/invariant");
|
|
13
12
|
const networkStatus_js_1 = require("./networkStatus.cjs");
|
|
14
13
|
const IGNORE = {};
|
|
15
|
-
const destructiveMethodCounts = new WeakMap();
|
|
16
|
-
function wrapDestructiveCacheMethod(cache, methodName) {
|
|
17
|
-
const original = cache[methodName];
|
|
18
|
-
if (typeof original === "function") {
|
|
19
|
-
// @ts-expect-error this is just too generic to be typed correctly
|
|
20
|
-
cache[methodName] = function () {
|
|
21
|
-
destructiveMethodCounts.set(cache,
|
|
22
|
-
// The %1e15 allows the count to wrap around to 0 safely every
|
|
23
|
-
// quadrillion evictions, so there's no risk of overflow. To be
|
|
24
|
-
// clear, this is more of a pedantic principle than something
|
|
25
|
-
// that matters in any conceivable practical scenario.
|
|
26
|
-
(destructiveMethodCounts.get(cache) + 1) % 1e15);
|
|
27
|
-
// @ts-expect-error this is just too generic to be typed correctly
|
|
28
|
-
return original.apply(this, arguments);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
14
|
const queryInfoIds = new WeakMap();
|
|
33
15
|
// A QueryInfo object represents a single network request, either initiated
|
|
34
16
|
// from the QueryManager or from an ObservableQuery.
|
|
@@ -42,60 +24,12 @@ class QueryInfo {
|
|
|
42
24
|
observableQuery;
|
|
43
25
|
incremental;
|
|
44
26
|
constructor(queryManager, observableQuery) {
|
|
45
|
-
|
|
27
|
+
this.cache = queryManager.cache;
|
|
46
28
|
const id = (queryInfoIds.get(queryManager) || 0) + 1;
|
|
47
29
|
queryInfoIds.set(queryManager, id);
|
|
48
30
|
this.id = id + "";
|
|
49
31
|
this.observableQuery = observableQuery;
|
|
50
32
|
this.queryManager = queryManager;
|
|
51
|
-
// Track how often cache.evict is called, since we want eviction to
|
|
52
|
-
// override the write-skipping logic in `shouldWrite`, by causing it to
|
|
53
|
-
// return true. Wrapping the cache.evict method is a bit of a hack, but it
|
|
54
|
-
// saves us from having to make eviction counting an official part of the
|
|
55
|
-
// ApolloCache API.
|
|
56
|
-
if (!destructiveMethodCounts.has(cache)) {
|
|
57
|
-
destructiveMethodCounts.set(cache, 0);
|
|
58
|
-
wrapDestructiveCacheMethod(cache, "evict");
|
|
59
|
-
wrapDestructiveCacheMethod(cache, "modify");
|
|
60
|
-
wrapDestructiveCacheMethod(cache, "reset");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @internal
|
|
65
|
-
* Tracks the last result written to the cache so that `shouldWrite` can skip
|
|
66
|
-
* an identical write. Since a `QueryInfo` only ever represents a single
|
|
67
|
-
* network request, this is shared by all `QueryInfo` instances of an
|
|
68
|
-
* `ObservableQuery`. A standalone `QueryInfo` keeps a local version.
|
|
69
|
-
*
|
|
70
|
-
* A network result that was explicitly asked for always takes precedence over
|
|
71
|
-
* what is already cached, so `ObservableQuery.refetch` and polling clear this
|
|
72
|
-
* value before starting their request.
|
|
73
|
-
*
|
|
74
|
-
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
75
|
-
*/
|
|
76
|
-
_lastWrite;
|
|
77
|
-
get lastWrite() {
|
|
78
|
-
return (this.observableQuery || this)._lastWrite;
|
|
79
|
-
}
|
|
80
|
-
set lastWrite(value) {
|
|
81
|
-
(this.observableQuery || this)._lastWrite = value;
|
|
82
|
-
}
|
|
83
|
-
resetLastWrite() {
|
|
84
|
-
this.lastWrite = void 0;
|
|
85
|
-
}
|
|
86
|
-
shouldWrite(result, variables) {
|
|
87
|
-
const { lastWrite } = this;
|
|
88
|
-
return (!lastWrite ||
|
|
89
|
-
// If cache.evict has been called since the last time we wrote this
|
|
90
|
-
// data into the cache, there's a chance writing this result into
|
|
91
|
-
// the cache will repair what was evicted.
|
|
92
|
-
lastWrite.dmCount !== destructiveMethodCounts.get(this.cache) ||
|
|
93
|
-
!(0, equality_1.equal)(variables, lastWrite.variables) ||
|
|
94
|
-
!(0, equality_1.equal)(result.data, lastWrite.result.data) ||
|
|
95
|
-
// We have to compare these values because its possible the final chunk
|
|
96
|
-
// emitted in the incremental result is just `hasNext: false`. This
|
|
97
|
-
// ensures we trigger a cache write when we get `isLastChunk: true`.
|
|
98
|
-
lastWrite.hasNext !== this.hasNext);
|
|
99
33
|
}
|
|
100
34
|
get hasNext() {
|
|
101
35
|
return this.incremental ? this.incremental.hasNext : false;
|
|
@@ -162,14 +96,9 @@ class QueryInfo {
|
|
|
162
96
|
(0, internal_1.hasDirectives)(["defer"], query))) {
|
|
163
97
|
result.dataState = "streaming";
|
|
164
98
|
}
|
|
165
|
-
if (skipCache) {
|
|
166
|
-
return result;
|
|
167
|
-
}
|
|
168
|
-
if (!shouldWriteResult(result, errorPolicy)) {
|
|
169
|
-
this.lastWrite = void 0;
|
|
99
|
+
if (skipCache || !shouldWriteResult(result, errorPolicy)) {
|
|
170
100
|
return result;
|
|
171
101
|
}
|
|
172
|
-
let written = false;
|
|
173
102
|
// Using a transaction here so we have a chance to read the result
|
|
174
103
|
// back from the cache before the watch callback fires as a result
|
|
175
104
|
// of writeQuery, so we can store the new diff quietly and ignore
|
|
@@ -185,55 +114,13 @@ class QueryInfo {
|
|
|
185
114
|
}
|
|
186
115
|
},
|
|
187
116
|
update: (cache) => {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// always write every network result into the cache, we enable
|
|
196
|
-
// feuds between queries competing to update the same data in
|
|
197
|
-
// incompatible ways, which can lead to an endless cycle of
|
|
198
|
-
// cache broadcasts and useless network requests. As with any
|
|
199
|
-
// feud, eventually one side must step back from the brink,
|
|
200
|
-
// letting the other side(s) have the last word(s). There may
|
|
201
|
-
// be other points where we could break this cycle, such as
|
|
202
|
-
// silencing the broadcast for cache.writeQuery (not a good
|
|
203
|
-
// idea, since it just delays the feud a bit) or somehow
|
|
204
|
-
// avoiding the network request that just happened (also bad,
|
|
205
|
-
// because the server could return useful new data). All
|
|
206
|
-
// options considered, skipping this cache write seems to be
|
|
207
|
-
// the least damaging place to break the cycle, because it
|
|
208
|
-
// reflects the intuition that we recently wrote this exact
|
|
209
|
-
// result into the cache, so the cache *should* already/still
|
|
210
|
-
// contain this data. If some other query has clobbered that
|
|
211
|
-
// data in the meantime, that's too bad, but there will be no
|
|
212
|
-
// winners if every query blindly reverts to its own version
|
|
213
|
-
// of the data. This approach also gives the network a chance
|
|
214
|
-
// to return new data, which will be written into the cache as
|
|
215
|
-
// usual, notifying only those queries that are directly
|
|
216
|
-
// affected by the cache updates, as usual. In the future, an
|
|
217
|
-
// even more sophisticated cache could perhaps prevent or
|
|
218
|
-
// mitigate the clobbering somehow, but that would make this
|
|
219
|
-
// particular cache write even less important, and thus
|
|
220
|
-
// skipping it would be even safer than it is today.
|
|
221
|
-
if (shouldWrite) {
|
|
222
|
-
cache.writeQuery({
|
|
223
|
-
query,
|
|
224
|
-
data: result.data,
|
|
225
|
-
variables,
|
|
226
|
-
overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
|
|
227
|
-
extensions: result.extensions,
|
|
228
|
-
});
|
|
229
|
-
this.lastWrite = {
|
|
230
|
-
result,
|
|
231
|
-
variables,
|
|
232
|
-
dmCount: destructiveMethodCounts.get(this.cache),
|
|
233
|
-
hasNext: this.hasNext,
|
|
234
|
-
};
|
|
235
|
-
written = true;
|
|
236
|
-
}
|
|
117
|
+
cache.writeQuery({
|
|
118
|
+
query,
|
|
119
|
+
data: result.data,
|
|
120
|
+
variables,
|
|
121
|
+
overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
|
|
122
|
+
extensions: result.extensions,
|
|
123
|
+
});
|
|
237
124
|
const { dataState, result: diffResult } = this.getDiff({
|
|
238
125
|
...diffOptions,
|
|
239
126
|
returnPartialData: returnPartialData &&
|
|
@@ -243,11 +130,10 @@ class QueryInfo {
|
|
|
243
130
|
}, this.getIncrementalInfo({ prune }));
|
|
244
131
|
if (dataState === "complete" ||
|
|
245
132
|
dataState === "streaming" ||
|
|
246
|
-
(returnPartialData && dataState === "partial"
|
|
133
|
+
(returnPartialData && dataState === "partial")) {
|
|
247
134
|
result = { ...result, data: diffResult, dataState };
|
|
248
135
|
}
|
|
249
136
|
else if (environment_1.__DEV__ &&
|
|
250
|
-
written &&
|
|
251
137
|
// A result that is still streaming is expected to read back
|
|
252
138
|
// incomplete until the remaining chunks arrive.
|
|
253
139
|
!this.hasNext) {
|
|
@@ -485,7 +371,7 @@ class QueryInfo {
|
|
|
485
371
|
exports.QueryInfo = QueryInfo;
|
|
486
372
|
function warnAboutPartialCacheResult(query, networkResult, diff) {
|
|
487
373
|
__DEV__ && invariant_1.invariant.warn(
|
|
488
|
-
|
|
374
|
+
90,
|
|
489
375
|
(0, internal_1.getOperationName)(query, "(anonymous)"),
|
|
490
376
|
diff.missing?.missing,
|
|
491
377
|
networkResult,
|