@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/policies.cjs +24 -2
  4. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  5. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  6. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  8. package/__cjs/core/ObservableQuery.cjs +10 -9
  9. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  10. package/__cjs/core/ObservableQuery.d.cts +1 -1
  11. package/__cjs/core/QueryInfo.cjs +2 -11
  12. package/__cjs/core/QueryInfo.cjs.map +1 -1
  13. package/__cjs/core/QueryInfo.d.cts +2 -2
  14. package/__cjs/core/QueryManager.cjs +14 -11
  15. package/__cjs/core/QueryManager.cjs.map +1 -1
  16. package/__cjs/invariantErrorCodes.cjs +13 -8
  17. package/__cjs/utilities/internal/index.cjs +3 -1
  18. package/__cjs/utilities/internal/index.cjs.map +1 -1
  19. package/__cjs/utilities/internal/index.d.cts +1 -0
  20. package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
  21. package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
  22. package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
  23. package/__cjs/version.cjs +1 -1
  24. package/cache/core/cache.js +1 -1
  25. package/cache/inmemory/policies.js +24 -2
  26. package/cache/inmemory/policies.js.map +1 -1
  27. package/cache/inmemory/readFromStore.js +3 -3
  28. package/cache/inmemory/readFromStore.js.map +1 -1
  29. package/cache/inmemory/writeToStore.js +4 -4
  30. package/core/ObservableQuery.d.ts +1 -1
  31. package/core/ObservableQuery.js +11 -10
  32. package/core/ObservableQuery.js.map +1 -1
  33. package/core/QueryInfo.d.ts +2 -2
  34. package/core/QueryInfo.js +3 -12
  35. package/core/QueryInfo.js.map +1 -1
  36. package/core/QueryManager.js +14 -11
  37. package/core/QueryManager.js.map +1 -1
  38. package/invariantErrorCodes.js +13 -8
  39. package/package.json +1 -1
  40. package/utilities/internal/index.d.ts +1 -0
  41. package/utilities/internal/index.js +1 -0
  42. package/utilities/internal/index.js.map +1 -1
  43. package/utilities/internal/toDiffWithDataState.d.ts +8 -0
  44. package/utilities/internal/toDiffWithDataState.js +17 -0
  45. package/utilities/internal/toDiffWithDataState.js.map +1 -0
  46. 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(116, result);
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(117, resultKeyNameFromField(field), result);
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(118, selection.name.value);
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(119, fieldName, parentType, childTypenames.length ?
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.DiffResult<TData>;
352
+ }): Cache.InternalDiffResultWithDataState<TData>;
353
353
  private getInitialResult;
354
354
  private resubscribeCache;
355
355
  private stableLastResult?;
@@ -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: diff.complete ? "complete"
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.complete ? "complete"
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") {