@apollo/client 4.3.3 → 4.3.5
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 +30 -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/helpers.cjs +5 -0
- package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +17 -6
- 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 +15 -3
- package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.cjs +21 -5
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +2 -0
- 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 +32 -16
- 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 +22 -33
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +1 -1
- package/__cjs/core/QueryManager.cjs +22 -15
- package/__cjs/core/QueryManager.cjs.map +1 -1
- 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/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +42 -43
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +0 -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/helpers.js +5 -0
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +3 -1
- package/cache/inmemory/inMemoryCache.js +17 -6
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +15 -3
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/policies.d.ts +2 -0
- package/cache/inmemory/policies.js +22 -6
- package/cache/inmemory/policies.js.map +1 -1
- 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 +33 -17
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.js +14 -14
- package/core/ObservableQuery.js +8 -8
- package/core/QueryInfo.d.ts +1 -1
- package/core/QueryInfo.js +23 -34
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +22 -15
- package/core/QueryManager.js.map +1 -1
- 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/react/hooks/useFragment.d.ts +42 -43
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +42 -43
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/utilities/internal/index.d.ts +0 -1
- package/utilities/internal/index.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
package/core/ApolloClient.js
CHANGED
|
@@ -71,8 +71,8 @@ export class ApolloClient {
|
|
|
71
71
|
*/
|
|
72
72
|
constructor(options) {
|
|
73
73
|
if (__DEV__) {
|
|
74
|
-
invariant(options.cache,
|
|
75
|
-
invariant(options.link,
|
|
74
|
+
invariant(options.cache, 71);
|
|
75
|
+
invariant(options.link, 72);
|
|
76
76
|
}
|
|
77
77
|
const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0, queryDeduplication = true, defaultOptions, defaultContext, assumeImmutableResults = cache.assumeImmutableResults, localState, devtools, dataMasking, link, incrementalHandler = new NotImplementedHandler(), experiments = [], refetchEventManager, } = options;
|
|
78
78
|
this.link = link;
|
|
@@ -260,12 +260,12 @@ export class ApolloClient {
|
|
|
260
260
|
if (refetchOn) {
|
|
261
261
|
const operationName = getOperationName(query, "(anonymous)");
|
|
262
262
|
if (!refetchEventManager) {
|
|
263
|
-
__DEV__ && invariant.warn(
|
|
263
|
+
__DEV__ && invariant.warn(73, operationName);
|
|
264
264
|
}
|
|
265
265
|
else if (typeof refetchOn === "object") {
|
|
266
266
|
Object.keys(refetchOn).forEach((source) => {
|
|
267
267
|
if (!refetchEventManager.hasSource(source)) {
|
|
268
|
-
__DEV__ && invariant.warn(
|
|
268
|
+
__DEV__ && invariant.warn(74, source, operationName);
|
|
269
269
|
}
|
|
270
270
|
});
|
|
271
271
|
}
|
|
@@ -287,13 +287,13 @@ export class ApolloClient {
|
|
|
287
287
|
options = mergeOptions(this.defaultOptions.query, options);
|
|
288
288
|
}
|
|
289
289
|
if (__DEV__) {
|
|
290
|
-
invariant(options.fetchPolicy !== "cache-and-network",
|
|
291
|
-
invariant(options.fetchPolicy !== "standby",
|
|
292
|
-
invariant(options.query,
|
|
293
|
-
invariant(options.query.kind === "Document",
|
|
294
|
-
invariant(!options.returnPartialData,
|
|
295
|
-
invariant(!options.pollInterval,
|
|
296
|
-
invariant(!options.notifyOnNetworkStatusChange,
|
|
290
|
+
invariant(options.fetchPolicy !== "cache-and-network", 75);
|
|
291
|
+
invariant(options.fetchPolicy !== "standby", 76);
|
|
292
|
+
invariant(options.query, 77);
|
|
293
|
+
invariant(options.query.kind === "Document", 78);
|
|
294
|
+
invariant(!options.returnPartialData, 79);
|
|
295
|
+
invariant(!options.pollInterval, 80);
|
|
296
|
+
invariant(!options.notifyOnNetworkStatusChange, 81);
|
|
297
297
|
}
|
|
298
298
|
return this.queryManager.query(options);
|
|
299
299
|
};
|
|
@@ -311,9 +311,9 @@ export class ApolloClient {
|
|
|
311
311
|
errorPolicy: "none",
|
|
312
312
|
}, this.defaultOptions.mutate), options);
|
|
313
313
|
if (__DEV__) {
|
|
314
|
-
invariant(optionsWithDefaults.mutation,
|
|
314
|
+
invariant(optionsWithDefaults.mutation, 82);
|
|
315
315
|
invariant(optionsWithDefaults.fetchPolicy === "network-only" ||
|
|
316
|
-
optionsWithDefaults.fetchPolicy === "no-cache",
|
|
316
|
+
optionsWithDefaults.fetchPolicy === "no-cache", 83);
|
|
317
317
|
}
|
|
318
318
|
checkDocument(optionsWithDefaults.mutation, OperationTypeNode.MUTATION);
|
|
319
319
|
return this.queryManager.mutate(optionsWithDefaults);
|
|
@@ -519,7 +519,7 @@ export class ApolloClient {
|
|
|
519
519
|
// result.queries and result.results instead, you shouldn't have to worry
|
|
520
520
|
// about preventing uncaught rejections for the Promise.all result.
|
|
521
521
|
result.catch((error) => {
|
|
522
|
-
__DEV__ && invariant.debug(
|
|
522
|
+
__DEV__ && invariant.debug(84, error);
|
|
523
523
|
});
|
|
524
524
|
return result;
|
|
525
525
|
}
|
package/core/ObservableQuery.js
CHANGED
|
@@ -102,7 +102,7 @@ export class ObservableQuery {
|
|
|
102
102
|
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
103
103
|
initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
|
|
104
104
|
if (options[variablesUnknownSymbol]) {
|
|
105
|
-
invariant(fetchPolicy === "standby",
|
|
105
|
+
invariant(fetchPolicy === "standby", 85);
|
|
106
106
|
this.variablesUnknown = true;
|
|
107
107
|
}
|
|
108
108
|
this.lastQuery = transformedQuery;
|
|
@@ -411,7 +411,7 @@ export class ObservableQuery {
|
|
|
411
411
|
const queryDef = getQueryDefinition(this.query);
|
|
412
412
|
const vars = queryDef.variableDefinitions;
|
|
413
413
|
if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
|
|
414
|
-
__DEV__ && invariant.warn(
|
|
414
|
+
__DEV__ && invariant.warn(86, variables, queryDef.name?.value || queryDef);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
if (variables && !equal(this.variables, variables)) {
|
|
@@ -426,7 +426,7 @@ export class ObservableQuery {
|
|
|
426
426
|
fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
|
|
427
427
|
invariant(
|
|
428
428
|
this.options.fetchPolicy !== "cache-only",
|
|
429
|
-
|
|
429
|
+
87,
|
|
430
430
|
getOperationName(this.query, "(anonymous)")
|
|
431
431
|
);
|
|
432
432
|
const combinedOptions = {
|
|
@@ -460,7 +460,7 @@ export class ObservableQuery {
|
|
|
460
460
|
let wasUpdated = false;
|
|
461
461
|
const isCached = this.options.fetchPolicy !== "no-cache";
|
|
462
462
|
if (!isCached) {
|
|
463
|
-
invariant(updateQuery,
|
|
463
|
+
invariant(updateQuery, 88);
|
|
464
464
|
}
|
|
465
465
|
const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
|
|
466
466
|
pushNotification({
|
|
@@ -634,7 +634,7 @@ export class ObservableQuery {
|
|
|
634
634
|
onError(error);
|
|
635
635
|
}
|
|
636
636
|
else {
|
|
637
|
-
invariant.error(
|
|
637
|
+
invariant.error(89, error);
|
|
638
638
|
}
|
|
639
639
|
return;
|
|
640
640
|
}
|
|
@@ -885,7 +885,7 @@ export class ObservableQuery {
|
|
|
885
885
|
if (!this.didWarnCacheOnlyPolling &&
|
|
886
886
|
pollInterval &&
|
|
887
887
|
fetchPolicy === "cache-only") {
|
|
888
|
-
__DEV__ && invariant.warn(
|
|
888
|
+
__DEV__ && invariant.warn(90, getOperationName(this.query, "(anonymous)"));
|
|
889
889
|
this.didWarnCacheOnlyPolling = true;
|
|
890
890
|
}
|
|
891
891
|
}
|
|
@@ -1511,7 +1511,7 @@ export class ObservableQuery {
|
|
|
1511
1511
|
}
|
|
1512
1512
|
export function logMissingFieldErrors(missing) {
|
|
1513
1513
|
if (__DEV__ && missing) {
|
|
1514
|
-
__DEV__ && invariant.debug(
|
|
1514
|
+
__DEV__ && invariant.debug(91, missing);
|
|
1515
1515
|
}
|
|
1516
1516
|
}
|
|
1517
1517
|
function isEqualQuery(a, b) {
|
|
@@ -1555,6 +1555,6 @@ function getTrackingOperatorPromise(defaultValue) {
|
|
|
1555
1555
|
return { promise, operator };
|
|
1556
1556
|
}
|
|
1557
1557
|
function warnOnFeud(query, diff) {
|
|
1558
|
-
__DEV__ && invariant.warn(
|
|
1558
|
+
__DEV__ && invariant.warn(92, getOperationName(query, "(anonymous)"), diff.missing?.missing);
|
|
1559
1559
|
}
|
|
1560
1560
|
//# sourceMappingURL=ObservableQuery.js.map
|
package/core/QueryInfo.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare class QueryInfo<TData, TVariables extends OperationVariables = Op
|
|
|
59
59
|
update?: MutationUpdaterFunction<TData, TVariables, TCache>;
|
|
60
60
|
keepRootFields?: boolean;
|
|
61
61
|
}): boolean;
|
|
62
|
-
markSubscriptionResult(result: FormattedExecutionResult<TData>, { document, variables, errorPolicy, cacheWriteBehavior, }: OperationInfo<TData, TVariables, CacheWriteBehavior.FORBID | CacheWriteBehavior.MERGE>):
|
|
62
|
+
markSubscriptionResult(result: FormattedExecutionResult<TData>, { document, variables, errorPolicy, cacheWriteBehavior, }: OperationInfo<TData, TVariables, CacheWriteBehavior.FORBID | CacheWriteBehavior.MERGE>): TData | null | undefined;
|
|
63
63
|
}
|
|
64
64
|
export {};
|
|
65
65
|
//# sourceMappingURL=QueryInfo.d.ts.map
|
package/core/QueryInfo.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Trie } from "@wry/trie";
|
|
2
1
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
3
|
-
import { getOperationName, graphQLResultHasError, handleIncrementalSymbol,
|
|
2
|
+
import { coerceScalarFieldsToParsed, getOperationName, graphQLResultHasError, handleIncrementalSymbol, toDiffWithDataState, } from "@apollo/client/utilities/internal";
|
|
4
3
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
5
4
|
import { NetworkStatus } from "./networkStatus.js";
|
|
6
5
|
const IGNORE = {};
|
|
@@ -67,26 +66,7 @@ export class QueryInfo {
|
|
|
67
66
|
...incrementalResult,
|
|
68
67
|
dataState: incrementalResult.data == null ? "empty" : "complete",
|
|
69
68
|
};
|
|
70
|
-
|
|
71
|
-
?.getPendingWithInfo?.()
|
|
72
|
-
.some((pending) => pending.type === "defer" && !pending.delivered);
|
|
73
|
-
if (hasPendingDefer ||
|
|
74
|
-
// The Defer20220824Handler cannot track pending/completed incremental
|
|
75
|
-
// chunks due to its data format so we naively set dataState to
|
|
76
|
-
// streaming if we are still processing chunks. The only case where
|
|
77
|
-
// streaming is incorrect and should actually be complete is when
|
|
78
|
-
// both a @defer and @stream boundary is present and the @defer chunk
|
|
79
|
-
// has completed before the `@stream` array.
|
|
80
|
-
//
|
|
81
|
-
// Assigning the naive "streaming" value avoids a much more expensive
|
|
82
|
-
// pass over `result.data` that would otherwise need to traverse the
|
|
83
|
-
// selection sets and evaluate the data object at each defer boundary
|
|
84
|
-
// to see if it fulfills the selection set. For such a narrow case where
|
|
85
|
-
// its incorrect on a format that is now outdated is not worth the
|
|
86
|
-
// fix so we are ok with reporting a `streaming` here.
|
|
87
|
-
(!this.incremental?.getPendingWithInfo &&
|
|
88
|
-
this.hasNext &&
|
|
89
|
-
hasDirectives(["defer"], query))) {
|
|
69
|
+
if (this.incremental?.isDeferPending()) {
|
|
90
70
|
result.dataState = "streaming";
|
|
91
71
|
}
|
|
92
72
|
if (skipCache || !shouldWriteResult(result, errorPolicy)) {
|
|
@@ -113,6 +93,9 @@ export class QueryInfo {
|
|
|
113
93
|
variables,
|
|
114
94
|
overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
|
|
115
95
|
extensions: result.extensions,
|
|
96
|
+
[handleIncrementalSymbol]: {
|
|
97
|
+
isDeferPending: this.incremental?.isDeferPending,
|
|
98
|
+
},
|
|
116
99
|
});
|
|
117
100
|
const { dataState, result: diffResult } = this.getDiff({
|
|
118
101
|
...diffOptions,
|
|
@@ -141,23 +124,18 @@ export class QueryInfo {
|
|
|
141
124
|
return result;
|
|
142
125
|
}
|
|
143
126
|
getIncrementalInfo({ prune }) {
|
|
144
|
-
const pending = this.incremental?.getPendingWithInfo?.() ?? [];
|
|
145
127
|
const streamInfo = this.incremental?.streamInfo;
|
|
146
128
|
const incrementalInfo = { streamInfo };
|
|
147
129
|
// We don't want to deliver stream items or complete defer boundaries
|
|
148
130
|
// for a network-only request if they haven't yet streamed from the
|
|
149
131
|
// network. We record all the still-pending paths so that cache.diff
|
|
150
132
|
// can prune complete defer/stream boundaries at those paths.
|
|
151
|
-
if (prune) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
incrementalInfo.deferInfo.lookupArray(item.path.concat(item.label || []));
|
|
156
|
-
}
|
|
157
|
-
else if (streamInfo && item.type === "stream") {
|
|
158
|
-
streamInfo.lookupArray(item.path).state.truncate = true;
|
|
159
|
-
}
|
|
133
|
+
if (prune && this.incremental?.tracksPending) {
|
|
134
|
+
const isDeferPending = this.incremental.isDeferPending;
|
|
135
|
+
if (isDeferPending()) {
|
|
136
|
+
incrementalInfo.isDeferPending ||= (path, label) => isDeferPending(path, label);
|
|
160
137
|
}
|
|
138
|
+
this.incremental.markStreamedPendingForTruncation?.();
|
|
161
139
|
}
|
|
162
140
|
return incrementalInfo;
|
|
163
141
|
}
|
|
@@ -197,6 +175,9 @@ export class QueryInfo {
|
|
|
197
175
|
query: mutation.document,
|
|
198
176
|
variables: mutation.variables,
|
|
199
177
|
extensions: result.extensions,
|
|
178
|
+
[handleIncrementalSymbol]: {
|
|
179
|
+
isDeferPending: this.incremental?.isDeferPending,
|
|
180
|
+
},
|
|
200
181
|
});
|
|
201
182
|
const { updateQueries } = mutation;
|
|
202
183
|
if (updateQueries) {
|
|
@@ -354,16 +335,24 @@ export class QueryInfo {
|
|
|
354
335
|
returnPartialData: true,
|
|
355
336
|
});
|
|
356
337
|
if (diff.complete) {
|
|
357
|
-
|
|
338
|
+
return diff.result;
|
|
358
339
|
}
|
|
359
340
|
}
|
|
360
341
|
this.queryManager.broadcastQueries();
|
|
361
342
|
}
|
|
343
|
+
else if (result.data != null &&
|
|
344
|
+
this.cache.configuresScalars() &&
|
|
345
|
+
shouldWriteResult(result, errorPolicy)) {
|
|
346
|
+
// The result is not written to the cache, so parse scalar values
|
|
347
|
+
// directly from the network result.
|
|
348
|
+
return coerceScalarFieldsToParsed(result.data, document, this.cache);
|
|
349
|
+
}
|
|
350
|
+
return result.data;
|
|
362
351
|
}
|
|
363
352
|
}
|
|
364
353
|
function warnAboutPartialCacheResult(query, networkResult, diff) {
|
|
365
354
|
__DEV__ && invariant.warn(
|
|
366
|
-
|
|
355
|
+
93,
|
|
367
356
|
getOperationName(query, "(anonymous)"),
|
|
368
357
|
diff.missing?.missing,
|
|
369
358
|
networkResult,
|