@apollo/client 4.1.0-alpha.7 → 4.1.0-alpha.9
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 +51 -0
- package/__cjs/cache/core/cache.cjs +64 -24
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +47 -0
- package/__cjs/cache/core/types/Cache.d.cts +38 -0
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +47 -0
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +47 -0
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +14 -5
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +5 -0
- package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +1 -0
- package/__cjs/cache/inmemory/writeToStore.cjs +6 -5
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +2 -1
- package/__cjs/core/ApolloClient.cjs +14 -14
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +21 -1
- package/__cjs/core/ObservableQuery.cjs +22 -8
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +1 -0
- package/__cjs/core/QueryInfo.cjs +3 -0
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryManager.cjs +27 -17
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +18 -2
- package/__cjs/invariantErrorCodes.cjs +39 -33
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +13 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +1 -1
- package/__cjs/link/error/index.cjs +1 -1
- package/__cjs/link/error/index.cjs.map +1 -1
- package/__cjs/link/error/index.d.cts +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.cjs +7 -4
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -0
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/utilities/internal/checkDocument.cjs +2 -4
- package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.cjs +21 -0
- package/__cjs/utilities/internal/constants.cjs.map +1 -0
- package/__cjs/utilities/internal/constants.d.cts +18 -0
- package/__cjs/utilities/internal/index.cjs +6 -1
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +2 -0
- package/__cjs/utilities/internal/mapObservableFragment.cjs +27 -0
- package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -0
- package/__cjs/utilities/internal/mapObservableFragment.d.cts +3 -0
- package/__cjs/utilities/internal/memoize.cjs +31 -0
- package/__cjs/utilities/internal/memoize.cjs.map +1 -0
- package/__cjs/utilities/internal/memoize.d.cts +8 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +47 -0
- package/cache/core/cache.js +65 -25
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +38 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +47 -0
- package/cache/inmemory/inMemoryCache.js +47 -0
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.d.ts +5 -0
- package/cache/inmemory/policies.js +14 -5
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +3 -3
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +1 -0
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +2 -1
- package/cache/inmemory/writeToStore.js +6 -5
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +21 -1
- package/core/ApolloClient.js +15 -15
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +1 -0
- package/core/ObservableQuery.js +23 -9
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js +3 -0
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +18 -2
- package/core/QueryManager.js +28 -18
- package/core/QueryManager.js.map +1 -1
- package/invariantErrorCodes.js +39 -33
- package/link/client-awareness/ClientAwarenessLink.d.ts +1 -1
- package/link/client-awareness/ClientAwarenessLink.js +13 -1
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/error/index.d.ts +1 -1
- package/link/error/index.js +1 -1
- package/link/error/index.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useLazyQuery.js +2 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useQuery.js +8 -5
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +2 -0
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.js +2 -1
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useQuery.js +9 -5
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.js +3 -1
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/utilities/internal/checkDocument.js +2 -4
- package/utilities/internal/checkDocument.js.map +1 -1
- package/utilities/internal/constants.d.ts +18 -0
- package/utilities/internal/constants.js +18 -0
- package/utilities/internal/constants.js.map +1 -0
- package/utilities/internal/index.d.ts +2 -0
- package/utilities/internal/index.js +2 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/mapObservableFragment.d.ts +3 -0
- package/utilities/internal/mapObservableFragment.js +24 -0
- package/utilities/internal/mapObservableFragment.js.map +1 -0
- package/utilities/internal/memoize.d.ts +8 -0
- package/utilities/internal/memoize.js +28 -0
- package/utilities/internal/memoize.js.map +1 -0
- package/version.js +1 -1
package/core/ObservableQuery.js
CHANGED
|
@@ -2,7 +2,7 @@ import { equal } from "@wry/equality";
|
|
|
2
2
|
import { BehaviorSubject, filter, Observable, share, Subject, tap } from "rxjs";
|
|
3
3
|
import { isNetworkRequestInFlight, isNetworkRequestSettled, } from "@apollo/client/utilities";
|
|
4
4
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
5
|
-
import { compact, equalByQuery, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
6
6
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
7
7
|
import { NetworkStatus } from "./networkStatus.js";
|
|
8
8
|
const { assign, hasOwnProperty } = Object;
|
|
@@ -23,6 +23,7 @@ const empty = {
|
|
|
23
23
|
export class ObservableQuery {
|
|
24
24
|
options;
|
|
25
25
|
queryName;
|
|
26
|
+
variablesUnknown = false;
|
|
26
27
|
/**
|
|
27
28
|
* @internal will be read and written from `QueryInfo`
|
|
28
29
|
*
|
|
@@ -74,6 +75,10 @@ export class ObservableQuery {
|
|
|
74
75
|
const { fetchPolicy = defaultFetchPolicy,
|
|
75
76
|
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
76
77
|
initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
|
|
78
|
+
if (options[variablesUnknownSymbol]) {
|
|
79
|
+
invariant(fetchPolicy === "standby", 80);
|
|
80
|
+
this.variablesUnknown = true;
|
|
81
|
+
}
|
|
77
82
|
this.lastQuery = transformedQuery;
|
|
78
83
|
this.options = {
|
|
79
84
|
...options,
|
|
@@ -375,7 +380,7 @@ export class ObservableQuery {
|
|
|
375
380
|
const queryDef = getQueryDefinition(this.query);
|
|
376
381
|
const vars = queryDef.variableDefinitions;
|
|
377
382
|
if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
|
|
378
|
-
__DEV__ && invariant.warn(
|
|
383
|
+
__DEV__ && invariant.warn(81, variables, queryDef.name?.value || queryDef);
|
|
379
384
|
}
|
|
380
385
|
}
|
|
381
386
|
if (variables && !equal(this.variables, variables)) {
|
|
@@ -391,7 +396,7 @@ export class ObservableQuery {
|
|
|
391
396
|
fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
|
|
392
397
|
invariant(
|
|
393
398
|
this.options.fetchPolicy !== "cache-only",
|
|
394
|
-
|
|
399
|
+
82,
|
|
395
400
|
getOperationName(this.query, "(anonymous)")
|
|
396
401
|
);
|
|
397
402
|
const combinedOptions = {
|
|
@@ -425,7 +430,7 @@ export class ObservableQuery {
|
|
|
425
430
|
let wasUpdated = false;
|
|
426
431
|
const isCached = this.options.fetchPolicy !== "no-cache";
|
|
427
432
|
if (!isCached) {
|
|
428
|
-
invariant(updateQuery,
|
|
433
|
+
invariant(updateQuery, 83);
|
|
429
434
|
}
|
|
430
435
|
const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
|
|
431
436
|
pushNotification({
|
|
@@ -434,13 +439,14 @@ export class ObservableQuery {
|
|
|
434
439
|
value: {},
|
|
435
440
|
}, { shouldEmit: 3 /* EmitBehavior.networkStatusChange */ });
|
|
436
441
|
const { promise, operator } = getTrackingOperatorPromise();
|
|
437
|
-
const { observable } = this.queryManager.fetchObservableWithInfo(combinedOptions, { networkStatus: NetworkStatus.fetchMore });
|
|
442
|
+
const { observable } = this.queryManager.fetchObservableWithInfo(combinedOptions, { networkStatus: NetworkStatus.fetchMore, exposeExtensions: true });
|
|
438
443
|
const subscription = observable
|
|
439
444
|
.pipe(operator, filter((notification) => notification.kind === "N" && notification.source === "network"))
|
|
440
445
|
.subscribe({
|
|
441
446
|
next: (notification) => {
|
|
442
447
|
wasUpdated = false;
|
|
443
448
|
const fetchMoreResult = notification.value;
|
|
449
|
+
const extensions = fetchMoreResult[extensionsSymbol];
|
|
444
450
|
if (isNetworkRequestSettled(notification.value.networkStatus)) {
|
|
445
451
|
finalize();
|
|
446
452
|
}
|
|
@@ -461,6 +467,7 @@ export class ObservableQuery {
|
|
|
461
467
|
variables: this.variables,
|
|
462
468
|
returnPartialData: true,
|
|
463
469
|
optimistic: false,
|
|
470
|
+
extensions,
|
|
464
471
|
}, (previous) => updateQuery(previous, {
|
|
465
472
|
fetchMoreResult: fetchMoreResult.data,
|
|
466
473
|
variables: combinedOptions.variables,
|
|
@@ -476,6 +483,7 @@ export class ObservableQuery {
|
|
|
476
483
|
query: combinedOptions.query,
|
|
477
484
|
variables: combinedOptions.variables,
|
|
478
485
|
data: fetchMoreResult.data,
|
|
486
|
+
extensions,
|
|
479
487
|
});
|
|
480
488
|
}
|
|
481
489
|
},
|
|
@@ -598,7 +606,7 @@ export class ObservableQuery {
|
|
|
598
606
|
onError(error);
|
|
599
607
|
}
|
|
600
608
|
else {
|
|
601
|
-
invariant.error(
|
|
609
|
+
invariant.error(84, error);
|
|
602
610
|
}
|
|
603
611
|
return;
|
|
604
612
|
}
|
|
@@ -842,7 +850,7 @@ export class ObservableQuery {
|
|
|
842
850
|
if (!this.didWarnCacheOnlyPolling &&
|
|
843
851
|
pollInterval &&
|
|
844
852
|
fetchPolicy === "cache-only") {
|
|
845
|
-
__DEV__ && invariant.warn(
|
|
853
|
+
__DEV__ && invariant.warn(85, getOperationName(this.query, "(anonymous)"));
|
|
846
854
|
this.didWarnCacheOnlyPolling = true;
|
|
847
855
|
}
|
|
848
856
|
}
|
|
@@ -917,6 +925,10 @@ export class ObservableQuery {
|
|
|
917
925
|
const oldVariables = this.variables;
|
|
918
926
|
const oldFetchPolicy = this.options.fetchPolicy;
|
|
919
927
|
const mergedOptions = compact(this.options, newOptions || {});
|
|
928
|
+
// This request will hit the network, so even if there are no variables,
|
|
929
|
+
// we now know that's intentional. (see #12996)
|
|
930
|
+
// Even if that happens only once, we want `variablesUnknown` to stay false permanently.
|
|
931
|
+
this.variablesUnknown &&= mergedOptions.fetchPolicy === "standby";
|
|
920
932
|
const options = useDisposableObservable ?
|
|
921
933
|
// Disposable Observable fetches receive a shallow copy of this.options
|
|
922
934
|
// (merged with newOptions), leaving this.options unmodified.
|
|
@@ -1186,7 +1198,9 @@ export class ObservableQuery {
|
|
|
1186
1198
|
// "fetchMore" having priority over "polling" or "loading" network statuses
|
|
1187
1199
|
// as for now we just take the "latest" operation that is still active,
|
|
1188
1200
|
// as that lines up best with previous behavior[]
|
|
1189
|
-
const operation = Array.from(this.activeOperations.values())
|
|
1201
|
+
const operation = Array.from(this.activeOperations.values())
|
|
1202
|
+
.reverse()
|
|
1203
|
+
.find((operation) => isEqualQuery(operation, this) && operation.override !== undefined);
|
|
1190
1204
|
return operation?.override ?? baseNetworkStatus;
|
|
1191
1205
|
}
|
|
1192
1206
|
abortActiveOperations() {
|
|
@@ -1330,7 +1344,7 @@ export class ObservableQuery {
|
|
|
1330
1344
|
}
|
|
1331
1345
|
export function logMissingFieldErrors(missing) {
|
|
1332
1346
|
if (__DEV__ && missing) {
|
|
1333
|
-
__DEV__ && invariant.debug(
|
|
1347
|
+
__DEV__ && invariant.debug(86, missing);
|
|
1334
1348
|
}
|
|
1335
1349
|
}
|
|
1336
1350
|
function isEqualQuery(a, b) {
|