@apollo/client 4.3.2 → 4.3.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 +26 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +4 -1
- package/__cjs/cache/core/types/Cache.d.cts +5 -0
- package/__cjs/cache/inmemory/entityStore.cjs +4 -4
- package/__cjs/cache/inmemory/inMemoryCache.cjs +15 -5
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +3 -1
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +5 -5
- package/__cjs/cache/inmemory/readFromStore.cjs +28 -10
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +7 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +29 -14
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +5 -2
- package/__cjs/core/ApolloClient.cjs +14 -14
- package/__cjs/core/ObservableQuery.cjs +8 -8
- package/__cjs/core/QueryInfo.cjs +13 -32
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryManager.cjs +12 -12
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/incremental/handlers/defer20220824.cjs +15 -2
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +5 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +58 -14
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +23 -12
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/incremental/types.d.cts +19 -1
- package/__cjs/invariantErrorCodes.cjs +64 -58
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +0 -1
- package/__cjs/utilities/internal/isDeferredFragment.cjs +24 -26
- package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -1
- package/__cjs/utilities/internal/isDeferredFragment.d.cts +1 -1
- package/__cjs/utilities/internal/isStreamField.cjs +24 -20
- package/__cjs/utilities/internal/isStreamField.cjs.map +1 -1
- package/__cjs/utilities/internal/isStreamField.d.cts +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +4 -1
- package/cache/core/cache.js +1 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +5 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/inmemory/entityStore.js +4 -4
- package/cache/inmemory/inMemoryCache.d.ts +3 -1
- package/cache/inmemory/inMemoryCache.js +15 -5
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +5 -5
- package/cache/inmemory/readFromStore.js +28 -10
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +7 -2
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +5 -2
- package/cache/inmemory/writeToStore.js +30 -15
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.js +14 -14
- package/core/ObservableQuery.js +8 -8
- package/core/QueryInfo.js +14 -33
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +12 -12
- package/core/RefetchEventManager.js +3 -3
- package/incremental/handlers/defer20220824.d.ts +5 -1
- package/incremental/handlers/defer20220824.js +15 -2
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +23 -12
- package/incremental/handlers/graphql17Alpha9.js +58 -14
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/handlers/notImplemented.js +1 -1
- package/incremental/types.d.ts +19 -1
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +64 -58
- package/package.json +1 -1
- package/utilities/internal/index.d.ts +0 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isDeferredFragment.d.ts +1 -1
- package/utilities/internal/isDeferredFragment.js +23 -25
- package/utilities/internal/isDeferredFragment.js.map +1 -1
- package/utilities/internal/isStreamField.d.ts +1 -1
- package/utilities/internal/isStreamField.js +23 -19
- package/utilities/internal/isStreamField.js.map +1 -1
- package/version.js +1 -1
- package/__cjs/utilities/internal/types/DeferInfo.cjs +0 -3
- package/__cjs/utilities/internal/types/DeferInfo.cjs.map +0 -1
- package/__cjs/utilities/internal/types/DeferInfo.d.cts +0 -10
- package/utilities/internal/types/DeferInfo.d.ts +0 -10
- package/utilities/internal/types/DeferInfo.js +0 -2
- package/utilities/internal/types/DeferInfo.js.map +0 -1
|
@@ -2,9 +2,10 @@ import type { FieldNode, SelectionSetNode } from "graphql";
|
|
|
2
2
|
import type { Cache, OperationVariables } from "@apollo/client";
|
|
3
3
|
import type { Reference, StoreObject } from "@apollo/client/utilities";
|
|
4
4
|
import type { FragmentMap, FragmentMapFunction } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { handleIncrementalSymbol } from "@apollo/client/utilities/internal";
|
|
5
6
|
import type { InMemoryCache } from "./inMemoryCache.cjs";
|
|
6
7
|
import type { StoreReader } from "./readFromStore.cjs";
|
|
7
|
-
import type { InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext } from "./types.cjs";
|
|
8
|
+
import type { DiffIncrementalInfo, InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext } from "./types.cjs";
|
|
8
9
|
export interface WriteContext extends ReadMergeModifyContext {
|
|
9
10
|
readonly written: {
|
|
10
11
|
[dataId: string]: SelectionSetNode[];
|
|
@@ -28,7 +29,9 @@ export declare class StoreWriter {
|
|
|
28
29
|
private reader?;
|
|
29
30
|
private fragments?;
|
|
30
31
|
constructor(cache: InMemoryCache, reader?: StoreReader | undefined, fragments?: InMemoryCacheConfig["fragments"]);
|
|
31
|
-
writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, }: Cache.WriteOptions<TData, TVariables>
|
|
32
|
+
writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, }: Cache.WriteOptions<TData, TVariables> & {
|
|
33
|
+
[handleIncrementalSymbol]?: DiffIncrementalInfo;
|
|
34
|
+
}): Reference | undefined;
|
|
32
35
|
private processSelectionSet;
|
|
33
36
|
private processFieldValue;
|
|
34
37
|
private flattenFields;
|
|
@@ -78,8 +78,8 @@ class ApolloClient {
|
|
|
78
78
|
*/
|
|
79
79
|
constructor(options) {
|
|
80
80
|
if (environment_1.__DEV__) {
|
|
81
|
-
(0, invariant_1.invariant)(options.cache,
|
|
82
|
-
(0, invariant_1.invariant)(options.link,
|
|
81
|
+
(0, invariant_1.invariant)(options.cache, 71);
|
|
82
|
+
(0, invariant_1.invariant)(options.link, 72);
|
|
83
83
|
}
|
|
84
84
|
const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0, queryDeduplication = true, defaultOptions, defaultContext, assumeImmutableResults = cache.assumeImmutableResults, localState, devtools, dataMasking, link, incrementalHandler = new incremental_1.NotImplementedHandler(), experiments = [], refetchEventManager, } = options;
|
|
85
85
|
this.link = link;
|
|
@@ -267,12 +267,12 @@ class ApolloClient {
|
|
|
267
267
|
if (refetchOn) {
|
|
268
268
|
const operationName = (0, internal_1.getOperationName)(query, "(anonymous)");
|
|
269
269
|
if (!refetchEventManager) {
|
|
270
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
270
|
+
__DEV__ && invariant_1.invariant.warn(73, operationName);
|
|
271
271
|
}
|
|
272
272
|
else if (typeof refetchOn === "object") {
|
|
273
273
|
Object.keys(refetchOn).forEach((source) => {
|
|
274
274
|
if (!refetchEventManager.hasSource(source)) {
|
|
275
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
275
|
+
__DEV__ && invariant_1.invariant.warn(74, source, operationName);
|
|
276
276
|
}
|
|
277
277
|
});
|
|
278
278
|
}
|
|
@@ -294,13 +294,13 @@ class ApolloClient {
|
|
|
294
294
|
options = (0, internal_1.mergeOptions)(this.defaultOptions.query, options);
|
|
295
295
|
}
|
|
296
296
|
if (environment_1.__DEV__) {
|
|
297
|
-
(0, invariant_1.invariant)(options.fetchPolicy !== "cache-and-network",
|
|
298
|
-
(0, invariant_1.invariant)(options.fetchPolicy !== "standby",
|
|
299
|
-
(0, invariant_1.invariant)(options.query,
|
|
300
|
-
(0, invariant_1.invariant)(options.query.kind === "Document",
|
|
301
|
-
(0, invariant_1.invariant)(!options.returnPartialData,
|
|
302
|
-
(0, invariant_1.invariant)(!options.pollInterval,
|
|
303
|
-
(0, invariant_1.invariant)(!options.notifyOnNetworkStatusChange,
|
|
297
|
+
(0, invariant_1.invariant)(options.fetchPolicy !== "cache-and-network", 75);
|
|
298
|
+
(0, invariant_1.invariant)(options.fetchPolicy !== "standby", 76);
|
|
299
|
+
(0, invariant_1.invariant)(options.query, 77);
|
|
300
|
+
(0, invariant_1.invariant)(options.query.kind === "Document", 78);
|
|
301
|
+
(0, invariant_1.invariant)(!options.returnPartialData, 79);
|
|
302
|
+
(0, invariant_1.invariant)(!options.pollInterval, 80);
|
|
303
|
+
(0, invariant_1.invariant)(!options.notifyOnNetworkStatusChange, 81);
|
|
304
304
|
}
|
|
305
305
|
return this.queryManager.query(options);
|
|
306
306
|
};
|
|
@@ -318,9 +318,9 @@ class ApolloClient {
|
|
|
318
318
|
errorPolicy: "none",
|
|
319
319
|
}, this.defaultOptions.mutate), options);
|
|
320
320
|
if (environment_1.__DEV__) {
|
|
321
|
-
(0, invariant_1.invariant)(optionsWithDefaults.mutation,
|
|
321
|
+
(0, invariant_1.invariant)(optionsWithDefaults.mutation, 82);
|
|
322
322
|
(0, invariant_1.invariant)(optionsWithDefaults.fetchPolicy === "network-only" ||
|
|
323
|
-
optionsWithDefaults.fetchPolicy === "no-cache",
|
|
323
|
+
optionsWithDefaults.fetchPolicy === "no-cache", 83);
|
|
324
324
|
}
|
|
325
325
|
(0, internal_1.checkDocument)(optionsWithDefaults.mutation, graphql_1.OperationTypeNode.MUTATION);
|
|
326
326
|
return this.queryManager.mutate(optionsWithDefaults);
|
|
@@ -526,7 +526,7 @@ class ApolloClient {
|
|
|
526
526
|
// result.queries and result.results instead, you shouldn't have to worry
|
|
527
527
|
// about preventing uncaught rejections for the Promise.all result.
|
|
528
528
|
result.catch((error) => {
|
|
529
|
-
__DEV__ && invariant_1.invariant.debug(
|
|
529
|
+
__DEV__ && invariant_1.invariant.debug(84, error);
|
|
530
530
|
});
|
|
531
531
|
return result;
|
|
532
532
|
}
|
|
@@ -110,7 +110,7 @@ class ObservableQuery {
|
|
|
110
110
|
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
111
111
|
initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
|
|
112
112
|
if (options[internal_1.variablesUnknownSymbol]) {
|
|
113
|
-
(0, invariant_1.invariant)(fetchPolicy === "standby",
|
|
113
|
+
(0, invariant_1.invariant)(fetchPolicy === "standby", 85);
|
|
114
114
|
this.variablesUnknown = true;
|
|
115
115
|
}
|
|
116
116
|
this.lastQuery = transformedQuery;
|
|
@@ -419,7 +419,7 @@ class ObservableQuery {
|
|
|
419
419
|
const queryDef = (0, internal_1.getQueryDefinition)(this.query);
|
|
420
420
|
const vars = queryDef.variableDefinitions;
|
|
421
421
|
if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
|
|
422
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
422
|
+
__DEV__ && invariant_1.invariant.warn(86, variables, queryDef.name?.value || queryDef);
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
if (variables && !(0, equality_1.equal)(this.variables, variables)) {
|
|
@@ -434,7 +434,7 @@ class ObservableQuery {
|
|
|
434
434
|
fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
|
|
435
435
|
(0, invariant_1.invariant)(
|
|
436
436
|
this.options.fetchPolicy !== "cache-only",
|
|
437
|
-
|
|
437
|
+
87,
|
|
438
438
|
(0, internal_1.getOperationName)(this.query, "(anonymous)")
|
|
439
439
|
);
|
|
440
440
|
const combinedOptions = {
|
|
@@ -468,7 +468,7 @@ class ObservableQuery {
|
|
|
468
468
|
let wasUpdated = false;
|
|
469
469
|
const isCached = this.options.fetchPolicy !== "no-cache";
|
|
470
470
|
if (!isCached) {
|
|
471
|
-
(0, invariant_1.invariant)(updateQuery,
|
|
471
|
+
(0, invariant_1.invariant)(updateQuery, 88);
|
|
472
472
|
}
|
|
473
473
|
const { finalize, pushNotification } = this.pushOperation(networkStatus_js_1.NetworkStatus.fetchMore);
|
|
474
474
|
pushNotification({
|
|
@@ -642,7 +642,7 @@ class ObservableQuery {
|
|
|
642
642
|
onError(error);
|
|
643
643
|
}
|
|
644
644
|
else {
|
|
645
|
-
invariant_1.invariant.error(
|
|
645
|
+
invariant_1.invariant.error(89, error);
|
|
646
646
|
}
|
|
647
647
|
return;
|
|
648
648
|
}
|
|
@@ -893,7 +893,7 @@ class ObservableQuery {
|
|
|
893
893
|
if (!this.didWarnCacheOnlyPolling &&
|
|
894
894
|
pollInterval &&
|
|
895
895
|
fetchPolicy === "cache-only") {
|
|
896
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
896
|
+
__DEV__ && invariant_1.invariant.warn(90, (0, internal_1.getOperationName)(this.query, "(anonymous)"));
|
|
897
897
|
this.didWarnCacheOnlyPolling = true;
|
|
898
898
|
}
|
|
899
899
|
}
|
|
@@ -1520,7 +1520,7 @@ class ObservableQuery {
|
|
|
1520
1520
|
exports.ObservableQuery = ObservableQuery;
|
|
1521
1521
|
function logMissingFieldErrors(missing) {
|
|
1522
1522
|
if (environment_1.__DEV__ && missing) {
|
|
1523
|
-
__DEV__ && invariant_1.invariant.debug(
|
|
1523
|
+
__DEV__ && invariant_1.invariant.debug(91, missing);
|
|
1524
1524
|
}
|
|
1525
1525
|
}
|
|
1526
1526
|
function isEqualQuery(a, b) {
|
|
@@ -1565,7 +1565,7 @@ function getTrackingOperatorPromise(defaultValue) {
|
|
|
1565
1565
|
}
|
|
1566
1566
|
function warnOnFeud(query, diff) {
|
|
1567
1567
|
__DEV__ && invariant_1.invariant.warn(
|
|
1568
|
-
|
|
1568
|
+
92,
|
|
1569
1569
|
(0, internal_1.getOperationName)(query, "(anonymous)"),
|
|
1570
1570
|
diff.missing?.missing
|
|
1571
1571
|
);
|
package/__cjs/core/QueryInfo.cjs
CHANGED
|
@@ -5,7 +5,6 @@ const {
|
|
|
5
5
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.QueryInfo = void 0;
|
|
8
|
-
const trie_1 = require("@wry/trie");
|
|
9
8
|
const environment_1 = require("@apollo/client/utilities/environment");
|
|
10
9
|
const internal_1 = require("@apollo/client/utilities/internal");
|
|
11
10
|
const invariant_1 = require("@apollo/client/utilities/invariant");
|
|
@@ -74,26 +73,7 @@ class QueryInfo {
|
|
|
74
73
|
...incrementalResult,
|
|
75
74
|
dataState: incrementalResult.data == null ? "empty" : "complete",
|
|
76
75
|
};
|
|
77
|
-
|
|
78
|
-
?.getPendingWithInfo?.()
|
|
79
|
-
.some((pending) => pending.type === "defer" && !pending.delivered);
|
|
80
|
-
if (hasPendingDefer ||
|
|
81
|
-
// The Defer20220824Handler cannot track pending/completed incremental
|
|
82
|
-
// chunks due to its data format so we naively set dataState to
|
|
83
|
-
// streaming if we are still processing chunks. The only case where
|
|
84
|
-
// streaming is incorrect and should actually be complete is when
|
|
85
|
-
// both a @defer and @stream boundary is present and the @defer chunk
|
|
86
|
-
// has completed before the `@stream` array.
|
|
87
|
-
//
|
|
88
|
-
// Assigning the naive "streaming" value avoids a much more expensive
|
|
89
|
-
// pass over `result.data` that would otherwise need to traverse the
|
|
90
|
-
// selection sets and evaluate the data object at each defer boundary
|
|
91
|
-
// to see if it fulfills the selection set. For such a narrow case where
|
|
92
|
-
// its incorrect on a format that is now outdated is not worth the
|
|
93
|
-
// fix so we are ok with reporting a `streaming` here.
|
|
94
|
-
(!this.incremental?.getPendingWithInfo &&
|
|
95
|
-
this.hasNext &&
|
|
96
|
-
(0, internal_1.hasDirectives)(["defer"], query))) {
|
|
76
|
+
if (this.incremental?.isDeferPending()) {
|
|
97
77
|
result.dataState = "streaming";
|
|
98
78
|
}
|
|
99
79
|
if (skipCache || !shouldWriteResult(result, errorPolicy)) {
|
|
@@ -120,6 +100,9 @@ class QueryInfo {
|
|
|
120
100
|
variables,
|
|
121
101
|
overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
|
|
122
102
|
extensions: result.extensions,
|
|
103
|
+
[internal_1.handleIncrementalSymbol]: {
|
|
104
|
+
isDeferPending: this.incremental?.isDeferPending,
|
|
105
|
+
},
|
|
123
106
|
});
|
|
124
107
|
const { dataState, result: diffResult } = this.getDiff({
|
|
125
108
|
...diffOptions,
|
|
@@ -148,23 +131,18 @@ class QueryInfo {
|
|
|
148
131
|
return result;
|
|
149
132
|
}
|
|
150
133
|
getIncrementalInfo({ prune }) {
|
|
151
|
-
const pending = this.incremental?.getPendingWithInfo?.() ?? [];
|
|
152
134
|
const streamInfo = this.incremental?.streamInfo;
|
|
153
135
|
const incrementalInfo = { streamInfo };
|
|
154
136
|
// We don't want to deliver stream items or complete defer boundaries
|
|
155
137
|
// for a network-only request if they haven't yet streamed from the
|
|
156
138
|
// network. We record all the still-pending paths so that cache.diff
|
|
157
139
|
// can prune complete defer/stream boundaries at those paths.
|
|
158
|
-
if (prune) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
incrementalInfo.deferInfo.lookupArray(item.path.concat(item.label || []));
|
|
163
|
-
}
|
|
164
|
-
else if (streamInfo && item.type === "stream") {
|
|
165
|
-
streamInfo.lookupArray(item.path).state.truncate = true;
|
|
166
|
-
}
|
|
140
|
+
if (prune && this.incremental?.tracksPending) {
|
|
141
|
+
const isDeferPending = this.incremental.isDeferPending;
|
|
142
|
+
if (isDeferPending()) {
|
|
143
|
+
incrementalInfo.isDeferPending ||= (path, label) => isDeferPending(path, label);
|
|
167
144
|
}
|
|
145
|
+
this.incremental.markStreamedPendingForTruncation?.();
|
|
168
146
|
}
|
|
169
147
|
return incrementalInfo;
|
|
170
148
|
}
|
|
@@ -204,6 +182,9 @@ class QueryInfo {
|
|
|
204
182
|
query: mutation.document,
|
|
205
183
|
variables: mutation.variables,
|
|
206
184
|
extensions: result.extensions,
|
|
185
|
+
[internal_1.handleIncrementalSymbol]: {
|
|
186
|
+
isDeferPending: this.incremental?.isDeferPending,
|
|
187
|
+
},
|
|
207
188
|
});
|
|
208
189
|
const { updateQueries } = mutation;
|
|
209
190
|
if (updateQueries) {
|
|
@@ -371,7 +352,7 @@ class QueryInfo {
|
|
|
371
352
|
exports.QueryInfo = QueryInfo;
|
|
372
353
|
function warnAboutPartialCacheResult(query, networkResult, diff) {
|
|
373
354
|
__DEV__ && invariant_1.invariant.warn(
|
|
374
|
-
|
|
355
|
+
93,
|
|
375
356
|
(0, internal_1.getOperationName)(query, "(anonymous)"),
|
|
376
357
|
diff.missing?.missing,
|
|
377
358
|
networkResult,
|