@apollo/client 4.3.0-alpha.5 → 4.3.0-alpha.7
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 +22 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +28 -6
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ObservableQuery.cjs +175 -62
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +4 -7
- package/__cjs/core/QueryInfo.cjs +13 -136
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +2 -26
- package/__cjs/core/QueryManager.cjs +26 -25
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/invariantErrorCodes.cjs +57 -32
- package/__cjs/utilities/internal/index.cjs +3 -1
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +1 -0
- package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
- package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
- package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.js +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +28 -6
- 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/writeToStore.js +4 -4
- package/core/ObservableQuery.d.ts +4 -7
- package/core/ObservableQuery.js +172 -63
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +3 -27
- package/core/QueryInfo.js +14 -137
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +26 -25
- package/core/QueryManager.js.map +1 -1
- package/core/RefetchEventManager.js +3 -3
- package/invariantErrorCodes.js +57 -32
- package/package.json +1 -1
- package/utilities/internal/index.d.ts +1 -0
- package/utilities/internal/index.js +1 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/toDiffWithDataState.d.ts +8 -0
- package/utilities/internal/toDiffWithDataState.js +17 -0
- package/utilities/internal/toDiffWithDataState.js.map +1 -0
- package/version.js +1 -1
package/core/QueryManager.js
CHANGED
|
@@ -99,7 +99,7 @@ export class QueryManager {
|
|
|
99
99
|
*/
|
|
100
100
|
stop() {
|
|
101
101
|
this.obsQueries.forEach((oq) => oq.stop());
|
|
102
|
-
this.cancelPendingFetches(newInvariantError(
|
|
102
|
+
this.cancelPendingFetches(newInvariantError(91));
|
|
103
103
|
}
|
|
104
104
|
cancelPendingFetches(error) {
|
|
105
105
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
@@ -112,7 +112,7 @@ export class QueryManager {
|
|
|
112
112
|
variables = this.getVariables(mutation, variables);
|
|
113
113
|
if (hasClientExports) {
|
|
114
114
|
if (__DEV__) {
|
|
115
|
-
invariant(this.localState,
|
|
115
|
+
invariant(this.localState, 92, getOperationName(mutation, "(anonymous)"));
|
|
116
116
|
}
|
|
117
117
|
variables = await this.localState.getExportedVariables({
|
|
118
118
|
client: this.client,
|
|
@@ -345,7 +345,7 @@ export class QueryManager {
|
|
|
345
345
|
// depend on values that previously existed in the data portion of the
|
|
346
346
|
// store. So, we cancel the promises and observers that we have issued
|
|
347
347
|
// so far and not yet resolved (in the case of queries).
|
|
348
|
-
this.cancelPendingFetches(newInvariantError(
|
|
348
|
+
this.cancelPendingFetches(newInvariantError(93));
|
|
349
349
|
this.obsQueries.forEach((observableQuery) => {
|
|
350
350
|
// Set loading to true so listeners don't trigger unless they want
|
|
351
351
|
// results with partial data.
|
|
@@ -415,10 +415,10 @@ export class QueryManager {
|
|
|
415
415
|
if (!included) {
|
|
416
416
|
const queryName = queryNames.get(nameOrQueryString);
|
|
417
417
|
if (queryName) {
|
|
418
|
-
__DEV__ && invariant.warn(
|
|
418
|
+
__DEV__ && invariant.warn(94, queryName);
|
|
419
419
|
}
|
|
420
420
|
else {
|
|
421
|
-
__DEV__ && invariant.warn(
|
|
421
|
+
__DEV__ && invariant.warn(95);
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
424
|
});
|
|
@@ -447,7 +447,7 @@ export class QueryManager {
|
|
|
447
447
|
if (__DEV__) {
|
|
448
448
|
invariant(
|
|
449
449
|
!this.getDocumentInfo(query).hasClientExports || this.localState,
|
|
450
|
-
|
|
450
|
+
96,
|
|
451
451
|
getOperationName(query, "(anonymous)")
|
|
452
452
|
);
|
|
453
453
|
}
|
|
@@ -592,14 +592,14 @@ export class QueryManager {
|
|
|
592
592
|
if (__DEV__) {
|
|
593
593
|
invariant(
|
|
594
594
|
this.localState,
|
|
595
|
-
|
|
595
|
+
97,
|
|
596
596
|
operation[0].toUpperCase() + operation.slice(1),
|
|
597
597
|
operationName ?? "(anonymous)"
|
|
598
598
|
);
|
|
599
599
|
}
|
|
600
600
|
invariant(
|
|
601
601
|
!hasIncrementalDirective,
|
|
602
|
-
|
|
602
|
+
98,
|
|
603
603
|
operation[0].toUpperCase() + operation.slice(1),
|
|
604
604
|
operationName ?? "(anonymous)"
|
|
605
605
|
);
|
|
@@ -642,7 +642,6 @@ export class QueryManager {
|
|
|
642
642
|
});
|
|
643
643
|
const hasErrors = graphQLResultHasError(result);
|
|
644
644
|
if (hasErrors && errorPolicy === "none") {
|
|
645
|
-
queryInfo.resetLastWrite();
|
|
646
645
|
observableQuery?.["resetNotifications"]();
|
|
647
646
|
const error = new CombinedGraphQLErrors(removeStreamDetailsFromExtensions(result));
|
|
648
647
|
dataStateErrorCache.set(error, dataState);
|
|
@@ -677,7 +676,6 @@ export class QueryManager {
|
|
|
677
676
|
return aqr;
|
|
678
677
|
}), catchError((error) => {
|
|
679
678
|
if (errorPolicy === "none") {
|
|
680
|
-
queryInfo.resetLastWrite();
|
|
681
679
|
observableQuery?.["resetNotifications"]();
|
|
682
680
|
throw error;
|
|
683
681
|
}
|
|
@@ -769,7 +767,7 @@ export class QueryManager {
|
|
|
769
767
|
// we deprecated and removed LocalState.
|
|
770
768
|
if (this.getDocumentInfo(normalized.query).hasClientExports) {
|
|
771
769
|
if (__DEV__) {
|
|
772
|
-
invariant(this.localState,
|
|
770
|
+
invariant(this.localState, 99, getOperationName(normalized.query, "(anonymous)"));
|
|
773
771
|
}
|
|
774
772
|
observable = from(this.localState.getExportedVariables({
|
|
775
773
|
client: this.client,
|
|
@@ -942,7 +940,7 @@ export class QueryManager {
|
|
|
942
940
|
!isFullyUnmaskedOperation(document) &&
|
|
943
941
|
!this.noCacheWarningsByCause.has(cause)) {
|
|
944
942
|
this.noCacheWarningsByCause.add(cause);
|
|
945
|
-
__DEV__ && invariant.warn(
|
|
943
|
+
__DEV__ && invariant.warn(100, getOperationName(document, `Unnamed ${operationType ?? "operation"}`));
|
|
946
944
|
}
|
|
947
945
|
}
|
|
948
946
|
return (this.dataMasking ?
|
|
@@ -956,31 +954,32 @@ export class QueryManager {
|
|
|
956
954
|
: data;
|
|
957
955
|
}
|
|
958
956
|
fetchQueryByPolicy({ query, variables, fetchPolicy, errorPolicy, returnPartialData, context, networkStatus, }, { cacheWriteBehavior, onCacheHit, queryInfo, observableQuery, exposeExtensions, }) {
|
|
959
|
-
const readCache = () =>
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
957
|
+
const readCache = () => {
|
|
958
|
+
return queryInfo.getDiff({
|
|
959
|
+
query,
|
|
960
|
+
variables,
|
|
961
|
+
returnPartialData: true,
|
|
962
|
+
optimistic: true,
|
|
963
|
+
});
|
|
964
|
+
};
|
|
965
965
|
const resultsFromCache = (diff, networkStatus) => {
|
|
966
966
|
const data = diff.result;
|
|
967
967
|
if (__DEV__ && !returnPartialData && data !== null) {
|
|
968
968
|
logMissingFieldErrors(diff.missing);
|
|
969
969
|
}
|
|
970
|
-
const toResult = (data) => {
|
|
970
|
+
const toResult = (data, dataState = diff.dataState) => {
|
|
971
971
|
// TODO: Eventually we should move this handling into
|
|
972
972
|
// queryInfo.getDiff() directly. Since getDiff is updated to return null
|
|
973
973
|
// on returnPartialData: false, we should take advantage of that instead
|
|
974
974
|
// of having to patch it elsewhere.
|
|
975
975
|
if (!diff.complete && !returnPartialData) {
|
|
976
976
|
data = undefined;
|
|
977
|
+
dataState = "empty";
|
|
977
978
|
}
|
|
978
979
|
return {
|
|
979
980
|
// TODO: Handle partial data
|
|
980
981
|
data: data,
|
|
981
|
-
dataState
|
|
982
|
-
: data ? "partial"
|
|
983
|
-
: "empty",
|
|
982
|
+
dataState,
|
|
984
983
|
loading: isNetworkRequestInFlight(networkStatus),
|
|
985
984
|
networkStatus,
|
|
986
985
|
partial: !diff.complete,
|
|
@@ -1004,7 +1003,7 @@ export class QueryManager {
|
|
|
1004
1003
|
(diff.complete || returnPartialData) &&
|
|
1005
1004
|
this.getDocumentInfo(query).hasForcedResolvers) {
|
|
1006
1005
|
if (__DEV__) {
|
|
1007
|
-
invariant(this.localState,
|
|
1006
|
+
invariant(this.localState, 101, getOperationName(query, "(anonymous)"));
|
|
1008
1007
|
}
|
|
1009
1008
|
onCacheHit();
|
|
1010
1009
|
return from(this.localState.execute({
|
|
@@ -1018,7 +1017,9 @@ export class QueryManager {
|
|
|
1018
1017
|
fetchPolicy,
|
|
1019
1018
|
}).then((resolved) => ({
|
|
1020
1019
|
kind: "N",
|
|
1021
|
-
value: toResult(resolved.data || void 0
|
|
1020
|
+
value: toResult(resolved.data || void 0, diff.complete ? "complete"
|
|
1021
|
+
: resolved.data ? "partial"
|
|
1022
|
+
: "empty"),
|
|
1022
1023
|
// Always attach the variables used for this fetch so @export
|
|
1023
1024
|
// resolution can update ObservableQuery.options.variables and
|
|
1024
1025
|
// resubscribe the cache watch under the correct variable set.
|
|
@@ -1113,7 +1114,7 @@ function validateDidEmitValue() {
|
|
|
1113
1114
|
didEmitValue = true;
|
|
1114
1115
|
},
|
|
1115
1116
|
complete() {
|
|
1116
|
-
invariant(didEmitValue,
|
|
1117
|
+
invariant(didEmitValue, 102);
|
|
1117
1118
|
},
|
|
1118
1119
|
});
|
|
1119
1120
|
}
|