@apollo/client 4.3.0-alpha.5 → 4.3.0-alpha.6
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 +10 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +24 -2
- 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 +10 -9
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +1 -1
- package/__cjs/core/QueryInfo.cjs +2 -11
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +2 -2
- package/__cjs/core/QueryManager.cjs +14 -11
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/invariantErrorCodes.cjs +13 -8
- 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/policies.js +24 -2
- 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 +1 -1
- package/core/ObservableQuery.js +11 -10
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +2 -2
- package/core/QueryInfo.js +3 -12
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +14 -11
- package/core/QueryManager.js.map +1 -1
- package/invariantErrorCodes.js +13 -8
- 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
|
@@ -68,7 +68,7 @@ export class StoreWriter {
|
|
|
68
68
|
path: [],
|
|
69
69
|
});
|
|
70
70
|
if (!isReference(ref)) {
|
|
71
|
-
throw newInvariantError(
|
|
71
|
+
throw newInvariantError(117, result);
|
|
72
72
|
}
|
|
73
73
|
// So far, the store has not been modified, so now it's time to process
|
|
74
74
|
// context.incomingById and merge those incoming fields into context.store.
|
|
@@ -230,7 +230,7 @@ export class StoreWriter {
|
|
|
230
230
|
// provide a default value, so its absence from the written data should
|
|
231
231
|
// not be cause for alarm.
|
|
232
232
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
233
|
-
invariant.error(
|
|
233
|
+
invariant.error(118, resultKeyNameFromField(field), result);
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
// Identify the result object, even if dataId was already provided,
|
|
@@ -378,7 +378,7 @@ export class StoreWriter {
|
|
|
378
378
|
else {
|
|
379
379
|
const fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
380
380
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
381
|
-
throw newInvariantError(
|
|
381
|
+
throw newInvariantError(119, selection.name.value);
|
|
382
382
|
}
|
|
383
383
|
if (fragment &&
|
|
384
384
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -550,7 +550,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
550
550
|
}
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
|
-
__DEV__ && invariant.warn(
|
|
553
|
+
__DEV__ && invariant.warn(120, fieldName, parentType, childTypenames.length ?
|
|
554
554
|
"either ensure all objects of type " +
|
|
555
555
|
childTypenames.join(" and ") +
|
|
556
556
|
" have an ID or a custom merge function, or "
|
|
@@ -349,7 +349,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
349
349
|
*/
|
|
350
350
|
getCacheDiff({ optimistic }?: {
|
|
351
351
|
optimistic?: boolean | undefined;
|
|
352
|
-
}): Cache.
|
|
352
|
+
}): Cache.InternalDiffResultWithDataState<TData>;
|
|
353
353
|
private getInitialResult;
|
|
354
354
|
private resubscribeCache;
|
|
355
355
|
private stableLastResult?;
|
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, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, handleIncrementalSymbol, preventUnhandledRejection, toDiffWithDataState, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
6
6
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
7
7
|
import { dataStateErrorCache } from "./dataStateErrorCache.js";
|
|
8
8
|
import { NetworkStatus } from "./networkStatus.js";
|
|
@@ -206,12 +206,13 @@ export class ObservableQuery {
|
|
|
206
206
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
207
207
|
*/
|
|
208
208
|
getCacheDiff({ optimistic = true } = {}) {
|
|
209
|
-
return this.cache.diff({
|
|
209
|
+
return toDiffWithDataState(this.cache.diff({
|
|
210
210
|
query: this.query,
|
|
211
211
|
variables: this.variables,
|
|
212
212
|
returnPartialData: true,
|
|
213
213
|
optimistic,
|
|
214
|
-
|
|
214
|
+
[handleIncrementalSymbol]: undefined,
|
|
215
|
+
}));
|
|
215
216
|
}
|
|
216
217
|
getInitialResult(initialFetchPolicy) {
|
|
217
218
|
let fetchPolicy = initialFetchPolicy || this.options.fetchPolicy;
|
|
@@ -221,16 +222,18 @@ export class ObservableQuery {
|
|
|
221
222
|
}
|
|
222
223
|
const cacheResult = () => {
|
|
223
224
|
const diff = this.getCacheDiff();
|
|
225
|
+
let { dataState } = diff;
|
|
224
226
|
// TODO: queryInfo.getDiff should handle this since cache.diff returns a
|
|
225
227
|
// null when returnPartialData is false
|
|
226
228
|
const data = this.options.returnPartialData || diff.complete ?
|
|
227
229
|
diff.result ?? undefined
|
|
228
230
|
: undefined;
|
|
231
|
+
if (data === undefined) {
|
|
232
|
+
dataState = "empty";
|
|
233
|
+
}
|
|
229
234
|
return this.maskResult({
|
|
230
235
|
data,
|
|
231
|
-
dataState
|
|
232
|
-
: data === undefined ? "empty"
|
|
233
|
-
: "partial",
|
|
236
|
+
dataState,
|
|
234
237
|
loading: !diff.complete,
|
|
235
238
|
networkStatus: diff.complete ? NetworkStatus.ready : NetworkStatus.loading,
|
|
236
239
|
partial: !diff.complete,
|
|
@@ -1156,9 +1159,7 @@ export class ObservableQuery {
|
|
|
1156
1159
|
kind: "N",
|
|
1157
1160
|
value: {
|
|
1158
1161
|
data: diff.result,
|
|
1159
|
-
dataState: diff.
|
|
1160
|
-
: diff.result ? "partial"
|
|
1161
|
-
: "empty",
|
|
1162
|
+
dataState: diff.dataState,
|
|
1162
1163
|
networkStatus: NetworkStatus.ready,
|
|
1163
1164
|
loading: false,
|
|
1164
1165
|
error: undefined,
|
|
@@ -1302,7 +1303,7 @@ export class ObservableQuery {
|
|
|
1302
1303
|
if (notification.source === "cache") {
|
|
1303
1304
|
result = notification.value;
|
|
1304
1305
|
if (result.networkStatus === NetworkStatus.ready &&
|
|
1305
|
-
result.partial &&
|
|
1306
|
+
result.dataState === "partial" &&
|
|
1306
1307
|
(!this.options.returnPartialData ||
|
|
1307
1308
|
previous.result.networkStatus === NetworkStatus.error) &&
|
|
1308
1309
|
this.options.fetchPolicy !== "cache-only") {
|