@apollo/client 4.3.0-alpha.2 → 4.3.0-alpha.4
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 +169 -0
- package/__cjs/cache/core/types/Cache.d.cts +25 -0
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +2 -2
- package/__cjs/cache/inmemory/entityStore.cjs +12 -6
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/entityStore.d.cts +1 -0
- package/__cjs/cache/inmemory/inMemoryCache.cjs +4 -0
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +7 -3
- package/__cjs/cache/inmemory/readFromStore.cjs +453 -43
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.d.cts +11 -2
- package/__cjs/cache/inmemory/types.d.cts +11 -1
- package/__cjs/cache/inmemory/writeToStore.cjs +2 -2
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.cjs +1 -3
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/QueryInfo.cjs +94 -16
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +12 -3
- package/__cjs/core/QueryManager.cjs +13 -18
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +0 -2
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +2 -4
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +20 -12
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +5 -5
- package/__cjs/incremental/types.d.cts +16 -3
- package/__cjs/utilities/caching/sizes.cjs.map +1 -1
- package/__cjs/utilities/caching/sizes.d.cts +39 -1
- package/__cjs/utilities/index.cjs.map +1 -1
- package/__cjs/utilities/index.d.cts +1 -0
- package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
- package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
- package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
- package/__cjs/utilities/internal/constants.cjs +20 -1
- package/__cjs/utilities/internal/constants.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.d.cts +19 -0
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
- package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
- package/__cjs/utilities/internal/index.cjs +13 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +7 -1
- package/__cjs/utilities/internal/isDeferredFragment.cjs +38 -0
- package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -0
- package/__cjs/utilities/internal/isDeferredFragment.d.cts +9 -0
- package/__cjs/utilities/internal/isStreamField.cjs +37 -0
- package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
- package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
- package/__cjs/utilities/internal/isTypenameField.cjs +7 -0
- package/__cjs/utilities/internal/isTypenameField.cjs.map +1 -0
- package/__cjs/utilities/internal/isTypenameField.d.cts +3 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
- package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
- package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
- package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
- package/__cjs/utilities/policies/pagination.cjs.map +1 -1
- package/__cjs/utilities/policies/pagination.d.cts +1 -1
- package/__cjs/utilities/subscriptions/relay/index.cjs +1 -0
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/types/Cache.d.ts +25 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/index.d.ts +2 -2
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +1 -0
- package/cache/inmemory/entityStore.js +12 -6
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +7 -3
- package/cache/inmemory/inMemoryCache.js +5 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +11 -2
- package/cache/inmemory/readFromStore.js +454 -44
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +12 -2
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +3 -3
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ObservableQuery.js +1 -3
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +12 -3
- package/core/QueryInfo.js +95 -17
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +0 -2
- package/core/QueryManager.js +13 -18
- package/core/QueryManager.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +2 -4
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +5 -5
- package/incremental/handlers/graphql17Alpha9.js +21 -13
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/types.d.ts +16 -3
- package/incremental/types.js.map +1 -1
- package/package.json +1 -1
- package/utilities/caching/sizes.d.ts +39 -1
- package/utilities/caching/sizes.js.map +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/internal/StreamArrayState.d.ts +12 -0
- package/utilities/internal/StreamArrayState.js +23 -0
- package/utilities/internal/StreamArrayState.js.map +1 -0
- package/utilities/internal/constants.d.ts +19 -0
- package/utilities/internal/constants.js +19 -0
- package/utilities/internal/constants.js.map +1 -1
- package/utilities/internal/getFragmentFromSelection.js +1 -1
- package/utilities/internal/getFragmentFromSelection.js.map +1 -1
- package/utilities/internal/getMemoryInternals.d.ts +4 -0
- package/utilities/internal/getMemoryInternals.js +6 -0
- package/utilities/internal/getMemoryInternals.js.map +1 -1
- package/utilities/internal/index.d.ts +7 -1
- package/utilities/internal/index.js +6 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isDeferredFragment.d.ts +9 -0
- package/utilities/internal/isDeferredFragment.js +35 -0
- package/utilities/internal/isDeferredFragment.js.map +1 -0
- package/utilities/internal/isStreamField.d.ts +9 -0
- package/utilities/internal/isStreamField.js +34 -0
- package/utilities/internal/isStreamField.js.map +1 -0
- package/utilities/internal/isTypenameField.d.ts +3 -0
- package/utilities/internal/isTypenameField.js +4 -0
- package/utilities/internal/isTypenameField.js.map +1 -0
- package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
- package/utilities/internal/makeStreamInfoTrie.js +14 -0
- package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
- package/utilities/internal/types/DeferInfo.d.ts +10 -0
- package/utilities/internal/types/DeferInfo.js +2 -0
- package/utilities/internal/types/DeferInfo.js.map +1 -0
- package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
- package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
- package/utilities/policies/pagination.d.ts +1 -1
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/subscriptions/relay/index.js +1 -0
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/version.js +1 -1
package/__cjs/core/QueryInfo.cjs
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryInfo = void 0;
|
|
4
4
|
const equality_1 = require("@wry/equality");
|
|
5
|
+
const trie_1 = require("@wry/trie");
|
|
5
6
|
const internal_1 = require("@apollo/client/utilities/internal");
|
|
6
7
|
const invariant_1 = require("@apollo/client/utilities/invariant");
|
|
8
|
+
const networkStatus_js_1 = require("./networkStatus.cjs");
|
|
7
9
|
const IGNORE = {};
|
|
8
10
|
const destructiveMethodCounts = new WeakMap();
|
|
9
11
|
function wrapDestructiveCacheMethod(cache, methodName) {
|
|
@@ -29,8 +31,6 @@ const queryInfoIds = new WeakMap();
|
|
|
29
31
|
// It is responsible for reporting results to the cache, merging and in a no-cache
|
|
30
32
|
// scenario accumulating the response.
|
|
31
33
|
class QueryInfo {
|
|
32
|
-
// TODO remove soon - this should be able to be handled by cancelling old operations before starting new ones
|
|
33
|
-
lastRequestId = 1;
|
|
34
34
|
cache;
|
|
35
35
|
queryManager;
|
|
36
36
|
id;
|
|
@@ -100,20 +100,49 @@ class QueryInfo {
|
|
|
100
100
|
}
|
|
101
101
|
return incoming;
|
|
102
102
|
}
|
|
103
|
-
markQueryResult(incoming, { document: query, variables, errorPolicy, cacheWriteBehavior, }) {
|
|
103
|
+
markQueryResult(incoming, { document: query, variables, errorPolicy, cacheWriteBehavior, returnPartialData, fetchPolicy, networkStatus, }) {
|
|
104
104
|
const diffOptions = {
|
|
105
105
|
query,
|
|
106
106
|
variables,
|
|
107
|
-
returnPartialData: true,
|
|
108
107
|
optimistic: true,
|
|
109
108
|
};
|
|
110
109
|
// Cancel the pending notify timeout (if it exists) to prevent extraneous network
|
|
111
110
|
// requests. To allow future notify timeouts, diff and dirty are reset as well.
|
|
112
111
|
this.observableQuery?.["resetNotifications"]();
|
|
113
112
|
const skipCache = cacheWriteBehavior === 0 /* CacheWriteBehavior.FORBID */;
|
|
114
|
-
const lastDiff = skipCache ? undefined : this.
|
|
115
|
-
|
|
113
|
+
const lastDiff = skipCache ? undefined : (this.getDiff({
|
|
114
|
+
...diffOptions,
|
|
115
|
+
// Always request partial data to ensure the network incremental
|
|
116
|
+
// result is merged with all existing data (especially true to
|
|
117
|
+
// maintain @stream arrays with partial list items in the right order)
|
|
118
|
+
returnPartialData: true,
|
|
119
|
+
}));
|
|
120
|
+
const incrementalResult = this.maybeHandleIncrementalResult(lastDiff?.result, incoming, query);
|
|
121
|
+
let result = {
|
|
122
|
+
...incrementalResult,
|
|
123
|
+
dataState: incrementalResult.data == null ? "empty" : "complete",
|
|
124
|
+
};
|
|
116
125
|
if (skipCache) {
|
|
126
|
+
const hasPendingDefer = this.incremental?.pending?.some((pending) => this.incremental?.getPendingType?.(pending.id) === "defer");
|
|
127
|
+
if (hasPendingDefer ||
|
|
128
|
+
// The Defer20220824Handler cannot track pending/completed incremental
|
|
129
|
+
// chunks due to its data format so we naively set dataState to
|
|
130
|
+
// streaming if we are still processing chunks. The only case where
|
|
131
|
+
// streaming is incorrect and should actually be complete is when
|
|
132
|
+
// both a @defer and @stream boundary is present and the @defer chunk
|
|
133
|
+
// has completed before the `@stream` array.
|
|
134
|
+
//
|
|
135
|
+
// Assigning the naive "streaming" value avoids a much more expensive
|
|
136
|
+
// pass over `result.data` that would otherwise need to traverse the
|
|
137
|
+
// selection sets and evaluate the data object at each defer boundary
|
|
138
|
+
// to see if it fulfills the selection set. For such a narrow case where
|
|
139
|
+
// its incorrect on a format that is now outdated is not worth the
|
|
140
|
+
// fix so we are ok with reporting a `streaming` here.
|
|
141
|
+
(!this.incremental?.pending &&
|
|
142
|
+
this.hasNext &&
|
|
143
|
+
(0, internal_1.hasDirectives)(["defer"], query))) {
|
|
144
|
+
result.dataState = "streaming";
|
|
145
|
+
}
|
|
117
146
|
return result;
|
|
118
147
|
}
|
|
119
148
|
if (shouldWriteResult(result, errorPolicy)) {
|
|
@@ -132,7 +161,8 @@ class QueryInfo {
|
|
|
132
161
|
}
|
|
133
162
|
},
|
|
134
163
|
update: (cache) => {
|
|
135
|
-
|
|
164
|
+
const shouldWrite = this.shouldWrite(result, variables);
|
|
165
|
+
if (shouldWrite) {
|
|
136
166
|
cache.writeQuery({
|
|
137
167
|
query,
|
|
138
168
|
data: result.data,
|
|
@@ -182,20 +212,27 @@ class QueryInfo {
|
|
|
182
212
|
if (lastDiff && lastDiff.complete) {
|
|
183
213
|
// Reuse data from the last good (complete) diff that we
|
|
184
214
|
// received, when possible.
|
|
185
|
-
result = {
|
|
215
|
+
result = {
|
|
216
|
+
...result,
|
|
217
|
+
data: lastDiff.result,
|
|
218
|
+
dataState: "complete",
|
|
219
|
+
};
|
|
186
220
|
return;
|
|
187
221
|
}
|
|
188
222
|
// If the previous this.diff was incomplete, fall through to
|
|
189
223
|
// re-reading the latest data with cache.diff, below.
|
|
190
224
|
}
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
225
|
+
const isNetworkOnly = fetchPolicy === "network-only" &&
|
|
226
|
+
networkStatus !== networkStatus_js_1.NetworkStatus.refetch;
|
|
227
|
+
const { dataState, result: diffResult } = this.getDiff({
|
|
228
|
+
...diffOptions,
|
|
229
|
+
// Never deliver partial data for network-only requests
|
|
230
|
+
returnPartialData: returnPartialData && !isNetworkOnly,
|
|
231
|
+
}, this.getIncrementalInfo(result, { isNetworkOnly }));
|
|
232
|
+
if (dataState === "complete" ||
|
|
233
|
+
(returnPartialData && dataState === "partial" && shouldWrite) ||
|
|
234
|
+
(this.hasNext && dataState === "streaming")) {
|
|
235
|
+
result = { ...result, data: diffResult, dataState };
|
|
199
236
|
}
|
|
200
237
|
},
|
|
201
238
|
});
|
|
@@ -205,6 +242,47 @@ class QueryInfo {
|
|
|
205
242
|
}
|
|
206
243
|
return result;
|
|
207
244
|
}
|
|
245
|
+
getIncrementalInfo(result, { isNetworkOnly }) {
|
|
246
|
+
const pending = this.incremental?.pending ?? [];
|
|
247
|
+
const streamInfo = result.extensions?.[internal_1.streamInfoSymbol]?.deref();
|
|
248
|
+
const incrementalInfo = { streamInfo };
|
|
249
|
+
// We don't want to deliver stream items or complete defer boundaries
|
|
250
|
+
// for a network-only request if they haven't yet streamed from the
|
|
251
|
+
// network. We record all the still-pending paths so that cache.diff
|
|
252
|
+
// can prune complete defer/stream boundaries at those paths.
|
|
253
|
+
if (isNetworkOnly) {
|
|
254
|
+
for (const item of pending) {
|
|
255
|
+
const type = this.incremental?.getPendingType?.(item.id);
|
|
256
|
+
if (type === "defer") {
|
|
257
|
+
incrementalInfo.deferInfo ||= new trie_1.Trie(true, () => true);
|
|
258
|
+
incrementalInfo.deferInfo.lookupArray(item.path);
|
|
259
|
+
}
|
|
260
|
+
else if (streamInfo && type === "stream") {
|
|
261
|
+
streamInfo.lookupArray(item.path).state.truncate = true;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return incrementalInfo;
|
|
266
|
+
}
|
|
267
|
+
getDiff(options, incrementalInfo) {
|
|
268
|
+
if (this.cache[internal_1.handleIncrementalSymbol]) {
|
|
269
|
+
return this.cache.diff({
|
|
270
|
+
...options,
|
|
271
|
+
[internal_1.handleIncrementalSymbol]: incrementalInfo || true,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
// returnPartialData is overridden for backwards compatibility with caches
|
|
275
|
+
// that don't handle incremental results. Without this, in-flight
|
|
276
|
+
// incremental cache data would come back null when returnPartialData is
|
|
277
|
+
// false due to the partial result.
|
|
278
|
+
const diff = this.cache.diff({ ...options, returnPartialData: true });
|
|
279
|
+
return {
|
|
280
|
+
...diff,
|
|
281
|
+
dataState: diff.complete ? "complete"
|
|
282
|
+
: diff.result === null ? "empty"
|
|
283
|
+
: "partial",
|
|
284
|
+
};
|
|
285
|
+
}
|
|
208
286
|
markMutationResult(incoming, mutation, cache = this.cache) {
|
|
209
287
|
const cacheWrites = [];
|
|
210
288
|
const skipCache = mutation.cacheWriteBehavior === 0 /* CacheWriteBehavior.FORBID */;
|