@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.
Files changed (52) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  4. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  5. package/__cjs/cache/inmemory/policies.cjs +28 -6
  6. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  8. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  10. package/__cjs/core/ObservableQuery.cjs +175 -62
  11. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  12. package/__cjs/core/ObservableQuery.d.cts +4 -7
  13. package/__cjs/core/QueryInfo.cjs +13 -136
  14. package/__cjs/core/QueryInfo.cjs.map +1 -1
  15. package/__cjs/core/QueryInfo.d.cts +2 -26
  16. package/__cjs/core/QueryManager.cjs +26 -25
  17. package/__cjs/core/QueryManager.cjs.map +1 -1
  18. package/__cjs/core/RefetchEventManager.cjs +3 -3
  19. package/__cjs/invariantErrorCodes.cjs +57 -32
  20. package/__cjs/utilities/internal/index.cjs +3 -1
  21. package/__cjs/utilities/internal/index.cjs.map +1 -1
  22. package/__cjs/utilities/internal/index.d.cts +1 -0
  23. package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
  24. package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
  25. package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
  26. package/__cjs/version.cjs +1 -1
  27. package/cache/core/cache.js +1 -1
  28. package/cache/inmemory/entityStore.js +3 -3
  29. package/cache/inmemory/key-extractor.js +1 -1
  30. package/cache/inmemory/policies.js +28 -6
  31. package/cache/inmemory/policies.js.map +1 -1
  32. package/cache/inmemory/readFromStore.js +3 -3
  33. package/cache/inmemory/readFromStore.js.map +1 -1
  34. package/cache/inmemory/writeToStore.js +4 -4
  35. package/core/ObservableQuery.d.ts +4 -7
  36. package/core/ObservableQuery.js +172 -63
  37. package/core/ObservableQuery.js.map +1 -1
  38. package/core/QueryInfo.d.ts +3 -27
  39. package/core/QueryInfo.js +14 -137
  40. package/core/QueryInfo.js.map +1 -1
  41. package/core/QueryManager.js +26 -25
  42. package/core/QueryManager.js.map +1 -1
  43. package/core/RefetchEventManager.js +3 -3
  44. package/invariantErrorCodes.js +57 -32
  45. package/package.json +1 -1
  46. package/utilities/internal/index.d.ts +1 -0
  47. package/utilities/internal/index.js +1 -0
  48. package/utilities/internal/index.js.map +1 -1
  49. package/utilities/internal/toDiffWithDataState.d.ts +8 -0
  50. package/utilities/internal/toDiffWithDataState.js +17 -0
  51. package/utilities/internal/toDiffWithDataState.js.map +1 -0
  52. package/version.js +1 -1
@@ -99,7 +99,7 @@ export class QueryManager {
99
99
  */
100
100
  stop() {
101
101
  this.obsQueries.forEach((oq) => oq.stop());
102
- this.cancelPendingFetches(newInvariantError(90));
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, 91, getOperationName(mutation, "(anonymous)"));
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(92));
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(93, queryName);
418
+ __DEV__ && invariant.warn(94, queryName);
419
419
  }
420
420
  else {
421
- __DEV__ && invariant.warn(94);
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
- 95,
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
- 96,
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
- 97,
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, 98, getOperationName(normalized.query, "(anonymous)"));
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(99, getOperationName(document, `Unnamed ${operationType ?? "operation"}`));
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 = () => this.cache.diff({
960
- query,
961
- variables,
962
- returnPartialData: true,
963
- optimistic: true,
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: diff.complete ? "complete"
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, 100, getOperationName(query, "(anonymous)"));
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, 101);
1117
+ invariant(didEmitValue, 102);
1117
1118
  },
1118
1119
  });
1119
1120
  }