@apollo/client 4.1.0-alpha.8 → 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 +45 -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/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/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/QueryManager.js
CHANGED
|
@@ -9,7 +9,7 @@ import { execute } from "@apollo/client/link";
|
|
|
9
9
|
import { maskFragment, maskOperation } from "@apollo/client/masking";
|
|
10
10
|
import { cacheSizes, DocumentTransform, isNetworkRequestInFlight, print, } from "@apollo/client/utilities";
|
|
11
11
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
12
|
-
import { AutoCleanedWeakCache, checkDocument, filterMap, getDefaultValues, getOperationDefinition, getOperationName, graphQLResultHasError, hasDirectives, hasForcedResolvers, isDocumentNode, isNonNullObject, makeUniqueId, removeDirectivesFromDocument, toQueryResult, } from "@apollo/client/utilities/internal";
|
|
12
|
+
import { AutoCleanedWeakCache, checkDocument, extensionsSymbol, filterMap, getDefaultValues, getOperationDefinition, getOperationName, graphQLResultHasError, hasDirectives, hasForcedResolvers, isDocumentNode, isNonNullObject, makeUniqueId, removeDirectivesFromDocument, toQueryResult, } from "@apollo/client/utilities/internal";
|
|
13
13
|
import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
|
|
14
14
|
import { NetworkStatus } from "./networkStatus.js";
|
|
15
15
|
import { logMissingFieldErrors, ObservableQuery } from "./ObservableQuery.js";
|
|
@@ -92,7 +92,7 @@ export class QueryManager {
|
|
|
92
92
|
*/
|
|
93
93
|
stop() {
|
|
94
94
|
this.obsQueries.forEach((oq) => oq.stop());
|
|
95
|
-
this.cancelPendingFetches(newInvariantError(
|
|
95
|
+
this.cancelPendingFetches(newInvariantError(87));
|
|
96
96
|
}
|
|
97
97
|
cancelPendingFetches(error) {
|
|
98
98
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
@@ -105,7 +105,7 @@ export class QueryManager {
|
|
|
105
105
|
variables = this.getVariables(mutation, variables);
|
|
106
106
|
if (hasClientExports) {
|
|
107
107
|
if (__DEV__) {
|
|
108
|
-
invariant(this.localState,
|
|
108
|
+
invariant(this.localState, 88, getOperationName(mutation, "(anonymous)"));
|
|
109
109
|
}
|
|
110
110
|
variables = await this.localState.getExportedVariables({
|
|
111
111
|
client: this.client,
|
|
@@ -342,7 +342,7 @@ export class QueryManager {
|
|
|
342
342
|
// depend on values that previously existed in the data portion of the
|
|
343
343
|
// store. So, we cancel the promises and observers that we have issued
|
|
344
344
|
// so far and not yet resolved (in the case of queries).
|
|
345
|
-
this.cancelPendingFetches(newInvariantError(
|
|
345
|
+
this.cancelPendingFetches(newInvariantError(89));
|
|
346
346
|
this.obsQueries.forEach((observableQuery) => {
|
|
347
347
|
// Set loading to true so listeners don't trigger unless they want
|
|
348
348
|
// results with partial data.
|
|
@@ -412,10 +412,10 @@ export class QueryManager {
|
|
|
412
412
|
if (!included) {
|
|
413
413
|
const queryName = queryNames.get(nameOrQueryString);
|
|
414
414
|
if (queryName) {
|
|
415
|
-
__DEV__ && invariant.warn(
|
|
415
|
+
__DEV__ && invariant.warn(90, queryName);
|
|
416
416
|
}
|
|
417
417
|
else {
|
|
418
|
-
__DEV__ && invariant.warn(
|
|
418
|
+
__DEV__ && invariant.warn(91);
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
});
|
|
@@ -444,7 +444,7 @@ export class QueryManager {
|
|
|
444
444
|
if (__DEV__) {
|
|
445
445
|
invariant(
|
|
446
446
|
!this.getDocumentInfo(query).hasClientExports || this.localState,
|
|
447
|
-
|
|
447
|
+
92,
|
|
448
448
|
getOperationName(query, "(anonymous)")
|
|
449
449
|
);
|
|
450
450
|
}
|
|
@@ -588,14 +588,14 @@ export class QueryManager {
|
|
|
588
588
|
if (__DEV__) {
|
|
589
589
|
invariant(
|
|
590
590
|
this.localState,
|
|
591
|
-
|
|
591
|
+
93,
|
|
592
592
|
operation[0].toUpperCase() + operation.slice(1),
|
|
593
593
|
operationName ?? "(anonymous)"
|
|
594
594
|
);
|
|
595
595
|
}
|
|
596
596
|
invariant(
|
|
597
597
|
!hasIncrementalDirective,
|
|
598
|
-
|
|
598
|
+
94,
|
|
599
599
|
operation[0].toUpperCase() + operation.slice(1),
|
|
600
600
|
operationName ?? "(anonymous)"
|
|
601
601
|
);
|
|
@@ -619,7 +619,7 @@ export class QueryManager {
|
|
|
619
619
|
})),
|
|
620
620
|
};
|
|
621
621
|
}
|
|
622
|
-
getResultsFromLink(options, { queryInfo, cacheWriteBehavior, observableQuery, }) {
|
|
622
|
+
getResultsFromLink(options, { queryInfo, cacheWriteBehavior, observableQuery, exposeExtensions, }) {
|
|
623
623
|
const requestId = (queryInfo.lastRequestId = this.generateRequestId());
|
|
624
624
|
const { errorPolicy } = options;
|
|
625
625
|
// Performing transformForLink here gives this.cache a chance to fill in
|
|
@@ -657,6 +657,9 @@ export class QueryManager {
|
|
|
657
657
|
partial: !result.data,
|
|
658
658
|
}),
|
|
659
659
|
};
|
|
660
|
+
if (exposeExtensions && "extensions" in result) {
|
|
661
|
+
aqr[extensionsSymbol] = result.extensions;
|
|
662
|
+
}
|
|
660
663
|
// In the case we start multiple network requests simultaneously, we
|
|
661
664
|
// want to ensure we properly set `data` if we're reporting on an old
|
|
662
665
|
// result which will not be caught by the conditional above that ends up
|
|
@@ -699,7 +702,7 @@ export class QueryManager {
|
|
|
699
702
|
// The initial networkStatus for this fetch, most often
|
|
700
703
|
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
|
|
701
704
|
// or setVariables.
|
|
702
|
-
networkStatus = NetworkStatus.loading, query = options.query, fetchQueryOperator = (x) => x, onCacheHit = () => { }, observableQuery, }) {
|
|
705
|
+
networkStatus = NetworkStatus.loading, query = options.query, fetchQueryOperator = (x) => x, onCacheHit = () => { }, observableQuery, exposeExtensions, }) {
|
|
703
706
|
const variables = this.getVariables(query, options.variables);
|
|
704
707
|
const defaults = this.defaultOptions.watchQuery;
|
|
705
708
|
let { fetchPolicy = (defaults && defaults.fetchPolicy) || "cache-first", errorPolicy = (defaults && defaults.errorPolicy) || "none", returnPartialData = false, notifyOnNetworkStatusChange = true, context = {}, } = options;
|
|
@@ -729,7 +732,13 @@ export class QueryManager {
|
|
|
729
732
|
normalized.refetchWritePolicy !== "merge") ?
|
|
730
733
|
1 /* CacheWriteBehavior.OVERWRITE */
|
|
731
734
|
: 2 /* CacheWriteBehavior.MERGE */;
|
|
732
|
-
const observableWithInfo = this.fetchQueryByPolicy(normalized, {
|
|
735
|
+
const observableWithInfo = this.fetchQueryByPolicy(normalized, {
|
|
736
|
+
queryInfo,
|
|
737
|
+
cacheWriteBehavior,
|
|
738
|
+
onCacheHit,
|
|
739
|
+
observableQuery,
|
|
740
|
+
exposeExtensions,
|
|
741
|
+
});
|
|
733
742
|
observableWithInfo.observable =
|
|
734
743
|
observableWithInfo.observable.pipe(fetchQueryOperator);
|
|
735
744
|
if (
|
|
@@ -763,7 +772,7 @@ export class QueryManager {
|
|
|
763
772
|
// we deprecated and removed LocalState.
|
|
764
773
|
if (this.getDocumentInfo(normalized.query).hasClientExports) {
|
|
765
774
|
if (__DEV__) {
|
|
766
|
-
invariant(this.localState,
|
|
775
|
+
invariant(this.localState, 95, getOperationName(normalized.query, "(anonymous)"));
|
|
767
776
|
}
|
|
768
777
|
observable = from(this.localState.getExportedVariables({
|
|
769
778
|
client: this.client,
|
|
@@ -798,7 +807,7 @@ export class QueryManager {
|
|
|
798
807
|
const includedQueriesByOq = new Map();
|
|
799
808
|
if (include) {
|
|
800
809
|
this.getObservableQueries(include).forEach((oq) => {
|
|
801
|
-
if (oq.options.fetchPolicy === "cache-only") {
|
|
810
|
+
if (oq.options.fetchPolicy === "cache-only" || oq["variablesUnknown"]) {
|
|
802
811
|
return;
|
|
803
812
|
}
|
|
804
813
|
const current = oq.getCurrentResult();
|
|
@@ -936,7 +945,7 @@ export class QueryManager {
|
|
|
936
945
|
!isFullyUnmaskedOperation(document) &&
|
|
937
946
|
!this.noCacheWarningsByCause.has(cause)) {
|
|
938
947
|
this.noCacheWarningsByCause.add(cause);
|
|
939
|
-
__DEV__ && invariant.warn(
|
|
948
|
+
__DEV__ && invariant.warn(96, getOperationName(document, `Unnamed ${operationType ?? "operation"}`));
|
|
940
949
|
}
|
|
941
950
|
}
|
|
942
951
|
return (this.dataMasking ?
|
|
@@ -949,7 +958,7 @@ export class QueryManager {
|
|
|
949
958
|
maskFragment(data, fragment, this.cache, fragmentName)
|
|
950
959
|
: data;
|
|
951
960
|
}
|
|
952
|
-
fetchQueryByPolicy({ query, variables, fetchPolicy, errorPolicy, returnPartialData, context, }, { cacheWriteBehavior, onCacheHit, queryInfo, observableQuery, }) {
|
|
961
|
+
fetchQueryByPolicy({ query, variables, fetchPolicy, errorPolicy, returnPartialData, context, }, { cacheWriteBehavior, onCacheHit, queryInfo, observableQuery, exposeExtensions, }) {
|
|
953
962
|
const readCache = () => this.cache.diff({
|
|
954
963
|
query,
|
|
955
964
|
variables,
|
|
@@ -994,7 +1003,7 @@ export class QueryManager {
|
|
|
994
1003
|
(diff.complete || returnPartialData) &&
|
|
995
1004
|
this.getDocumentInfo(query).hasForcedResolvers) {
|
|
996
1005
|
if (__DEV__) {
|
|
997
|
-
invariant(this.localState,
|
|
1006
|
+
invariant(this.localState, 97, getOperationName(query, "(anonymous)"));
|
|
998
1007
|
}
|
|
999
1008
|
onCacheHit();
|
|
1000
1009
|
return from(this.localState.execute({
|
|
@@ -1033,6 +1042,7 @@ export class QueryManager {
|
|
|
1033
1042
|
cacheWriteBehavior,
|
|
1034
1043
|
queryInfo,
|
|
1035
1044
|
observableQuery,
|
|
1045
|
+
exposeExtensions,
|
|
1036
1046
|
}).pipe(validateDidEmitValue(), materialize(), map((result) => ({
|
|
1037
1047
|
...result,
|
|
1038
1048
|
source: "network",
|
|
@@ -1086,7 +1096,7 @@ function validateDidEmitValue() {
|
|
|
1086
1096
|
didEmitValue = true;
|
|
1087
1097
|
},
|
|
1088
1098
|
complete() {
|
|
1089
|
-
invariant(didEmitValue,
|
|
1099
|
+
invariant(didEmitValue, 98);
|
|
1090
1100
|
},
|
|
1091
1101
|
});
|
|
1092
1102
|
}
|