@apollo/client 4.0.0-alpha.20 → 4.0.0-alpha.21

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 (90) hide show
  1. package/CHANGELOG.md +10 -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 +4 -4
  6. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  8. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  9. package/__cjs/core/ApolloClient.cjs +10 -10
  10. package/__cjs/core/ObservableQuery.cjs +15 -11
  11. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  12. package/__cjs/core/ObservableQuery.d.cts +1 -2
  13. package/__cjs/core/QueryInfo.cjs +223 -34
  14. package/__cjs/core/QueryInfo.cjs.map +1 -1
  15. package/__cjs/core/QueryInfo.d.cts +34 -24
  16. package/__cjs/core/QueryManager.cjs +75 -256
  17. package/__cjs/core/QueryManager.cjs.map +1 -1
  18. package/__cjs/core/QueryManager.d.cts +4 -36
  19. package/__cjs/core/networkStatus.cjs +7 -1
  20. package/__cjs/core/networkStatus.cjs.map +1 -1
  21. package/__cjs/core/networkStatus.d.cts +7 -1
  22. package/__cjs/invariantErrorCodes.cjs +64 -69
  23. package/__cjs/link/core/ApolloLink.cjs +2 -2
  24. package/__cjs/link/http/checkFetcher.cjs +1 -1
  25. package/__cjs/link/http/createHttpLink.cjs +1 -1
  26. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  27. package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
  28. package/__cjs/link/persisted-queries/index.cjs +2 -2
  29. package/__cjs/link/utils/validateOperation.cjs +1 -1
  30. package/__cjs/local-state/LocalState.cjs +10 -10
  31. package/__cjs/masking/maskDefinition.cjs.map +1 -1
  32. package/__cjs/masking/maskFragment.cjs +0 -8
  33. package/__cjs/masking/maskFragment.cjs.map +1 -1
  34. package/__cjs/masking/maskOperation.cjs +0 -8
  35. package/__cjs/masking/maskOperation.cjs.map +1 -1
  36. package/__cjs/masking/utils.cjs +3 -11
  37. package/__cjs/masking/utils.cjs.map +1 -1
  38. package/__cjs/masking/utils.d.cts +0 -1
  39. package/__cjs/react/hooks/useLazyQuery.cjs +1 -2
  40. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  41. package/__cjs/react/hooks/useLazyQuery.d.cts +0 -8
  42. package/__cjs/utilities/index.cjs +1 -16
  43. package/__cjs/utilities/index.cjs.map +1 -1
  44. package/__cjs/utilities/index.d.cts +0 -13
  45. package/__cjs/version.cjs +1 -1
  46. package/cache/core/cache.js +1 -1
  47. package/cache/inmemory/entityStore.js +3 -3
  48. package/cache/inmemory/key-extractor.js +1 -1
  49. package/cache/inmemory/policies.js +4 -4
  50. package/cache/inmemory/policies.js.map +1 -1
  51. package/cache/inmemory/readFromStore.js +2 -2
  52. package/cache/inmemory/writeToStore.js +4 -4
  53. package/core/ApolloClient.js +10 -10
  54. package/core/ObservableQuery.d.ts +1 -2
  55. package/core/ObservableQuery.js +15 -11
  56. package/core/ObservableQuery.js.map +1 -1
  57. package/core/QueryInfo.d.ts +34 -24
  58. package/core/QueryInfo.js +221 -34
  59. package/core/QueryInfo.js.map +1 -1
  60. package/core/QueryManager.d.ts +4 -36
  61. package/core/QueryManager.js +77 -258
  62. package/core/QueryManager.js.map +1 -1
  63. package/core/networkStatus.d.ts +7 -1
  64. package/core/networkStatus.js +7 -1
  65. package/core/networkStatus.js.map +1 -1
  66. package/invariantErrorCodes.js +64 -69
  67. package/link/core/ApolloLink.js +2 -2
  68. package/link/http/checkFetcher.js +1 -1
  69. package/link/http/createHttpLink.js +1 -1
  70. package/link/http/parseAndCheckHttpResponse.js +1 -1
  71. package/link/http/serializeFetchParameter.js +1 -1
  72. package/link/persisted-queries/index.js +2 -2
  73. package/link/utils/validateOperation.js +1 -1
  74. package/local-state/LocalState.js +10 -10
  75. package/masking/maskDefinition.js.map +1 -1
  76. package/masking/maskFragment.js +0 -8
  77. package/masking/maskFragment.js.map +1 -1
  78. package/masking/maskOperation.js +0 -8
  79. package/masking/maskOperation.js.map +1 -1
  80. package/masking/utils.d.ts +0 -1
  81. package/masking/utils.js +3 -10
  82. package/masking/utils.js.map +1 -1
  83. package/package.json +1 -1
  84. package/react/hooks/useLazyQuery.d.ts +0 -8
  85. package/react/hooks/useLazyQuery.js +1 -2
  86. package/react/hooks/useLazyQuery.js.map +1 -1
  87. package/utilities/index.d.ts +0 -13
  88. package/utilities/index.js +0 -12
  89. package/utilities/index.js.map +1 -1
  90. package/version.js +1 -1
@@ -195,7 +195,7 @@ export class StoreReader {
195
195
  else {
196
196
  const fragment = getFragmentFromSelection(selection, context.lookupFragment);
197
197
  if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
198
- throw newInvariantError(103, selection.name.value);
198
+ throw newInvariantError(102, selection.name.value);
199
199
  }
200
200
  if (fragment && policies.fragmentMatches(fragment, typename)) {
201
201
  fragment.selectionSet.selections.forEach(workSet.add, workSet);
@@ -278,7 +278,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
278
278
  if (isNonNullObject(value)) {
279
279
  invariant(
280
280
  !isReference(value),
281
- 104,
281
+ 103,
282
282
  getTypenameFromStoreObject(store, value),
283
283
  field.name.value
284
284
  );
@@ -66,7 +66,7 @@ export class StoreWriter {
66
66
  context,
67
67
  });
68
68
  if (!isReference(ref)) {
69
- throw newInvariantError(105, result);
69
+ throw newInvariantError(104, result);
70
70
  }
71
71
  // So far, the store has not been modified, so now it's time to process
72
72
  // context.incomingById and merge those incoming fields into context.store.
@@ -216,7 +216,7 @@ export class StoreWriter {
216
216
  // provide a default value, so its absence from the written data should
217
217
  // not be cause for alarm.
218
218
  !policies.getReadFunction(typename, field.name.value)) {
219
- __DEV__ && invariant.error(106, resultKeyNameFromField(field), result);
219
+ __DEV__ && invariant.error(105, resultKeyNameFromField(field), result);
220
220
  }
221
221
  });
222
222
  // Identify the result object, even if dataId was already provided,
@@ -363,7 +363,7 @@ export class StoreWriter {
363
363
  else {
364
364
  const fragment = getFragmentFromSelection(selection, context.lookupFragment);
365
365
  if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
366
- throw newInvariantError(107, selection.name.value);
366
+ throw newInvariantError(106, selection.name.value);
367
367
  }
368
368
  if (fragment &&
369
369
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
@@ -535,7 +535,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
535
535
  }
536
536
  });
537
537
  }
538
- __DEV__ && invariant.warn(108, fieldName, parentType, childTypenames.length ?
538
+ __DEV__ && invariant.warn(107, fieldName, parentType, childTypenames.length ?
539
539
  "either ensure all objects of type " +
540
540
  childTypenames.join(" and ") +
541
541
  " have an ID or a custom merge function, or "
@@ -69,8 +69,8 @@ export class ApolloClient {
69
69
  */
70
70
  constructor(options) {
71
71
  if (__DEV__) {
72
- invariant(options.cache, 67);
73
- invariant(options.link, 68);
72
+ invariant(options.cache, 66);
73
+ invariant(options.link, 67);
74
74
  }
75
75
  const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0,
76
76
  // Expose the client instance as window.__APOLLO_CLIENT__ and call
@@ -232,13 +232,13 @@ export class ApolloClient {
232
232
  options = mergeOptions(this.defaultOptions.query, options);
233
233
  }
234
234
  if (__DEV__) {
235
- invariant(options.fetchPolicy !== "cache-and-network", 69);
236
- invariant(options.fetchPolicy !== "standby", 70);
237
- invariant(options.query, 71);
238
- invariant(options.query.kind === "Document", 72);
239
- invariant(!options.returnPartialData, 73);
240
- invariant(!options.pollInterval, 74);
241
- invariant(!options.notifyOnNetworkStatusChange, 75);
235
+ invariant(options.fetchPolicy !== "cache-and-network", 68);
236
+ invariant(options.fetchPolicy !== "standby", 69);
237
+ invariant(options.query, 70);
238
+ invariant(options.query.kind === "Document", 71);
239
+ invariant(!options.returnPartialData, 72);
240
+ invariant(!options.pollInterval, 73);
241
+ invariant(!options.notifyOnNetworkStatusChange, 74);
242
242
  checkDocument(options.query, OperationTypeNode.QUERY);
243
243
  }
244
244
  return this.queryManager.query(options);
@@ -462,7 +462,7 @@ export class ApolloClient {
462
462
  // result.queries and result.results instead, you shouldn't have to worry
463
463
  // about preventing uncaught rejections for the Promise.all result.
464
464
  result.catch((error) => {
465
- __DEV__ && invariant.debug(76, error);
465
+ __DEV__ && invariant.debug(75, error);
466
466
  });
467
467
  return result;
468
468
  }
@@ -4,7 +4,6 @@ import { Observable } from "rxjs";
4
4
  import type { Cache, MissingFieldError } from "@apollo/client/cache";
5
5
  import type { MissingTree } from "@apollo/client/cache";
6
6
  import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
7
- import type { LastWrite } from "./QueryInfo.js";
8
7
  import type { QueryManager } from "./QueryManager.js";
9
8
  import type { ApolloQueryResult, DefaultContext, OperationVariables, QueryResult, TypedDocumentNode } from "./types.js";
10
9
  import type { ErrorPolicy, FetchMoreQueryOptions, NextFetchPolicyContext, RefetchWritePolicy, SubscribeToMoreOptions, UpdateQueryMapFn, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
@@ -177,7 +176,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
177
176
  *
178
177
  * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
179
178
  */
180
- _lastWrite?: LastWrite;
179
+ _lastWrite?: unknown;
181
180
  get query(): TypedDocumentNode<TData, TVariables>;
182
181
  /**
183
182
  * An object containing the variables that were provided for the query.
@@ -5,7 +5,6 @@ import { compact, filterMap, getOperationDefinition, getQueryDefinition, prevent
5
5
  import { invariant } from "@apollo/client/utilities/invariant";
6
6
  import { equalByQuery } from "./equalByQuery.js";
7
7
  import { isNetworkRequestInFlight, NetworkStatus } from "./networkStatus.js";
8
- import { QueryInfo } from "./QueryInfo.js";
9
8
  const { assign, hasOwnProperty } = Object;
10
9
  const uninitialized = {
11
10
  loading: true,
@@ -346,7 +345,7 @@ export class ObservableQuery {
346
345
  const queryDef = getQueryDefinition(this.query);
347
346
  const vars = queryDef.variableDefinitions;
348
347
  if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
349
- __DEV__ && invariant.warn(77, variables, queryDef.name?.value || queryDef);
348
+ __DEV__ && invariant.warn(76, variables, queryDef.name?.value || queryDef);
350
349
  }
351
350
  }
352
351
  if (variables && !equal(this.variables, variables)) {
@@ -395,7 +394,7 @@ export class ObservableQuery {
395
394
  const updateQuery = fetchMoreOptions?.updateQuery;
396
395
  const isCached = this.options.fetchPolicy !== "no-cache";
397
396
  if (!isCached) {
398
- invariant(updateQuery, 78);
397
+ invariant(updateQuery, 77);
399
398
  }
400
399
  const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
401
400
  pushNotification({
@@ -528,7 +527,7 @@ export class ObservableQuery {
528
527
  onError(error);
529
528
  }
530
529
  else {
531
- __DEV__ && invariant.error(79, error);
530
+ __DEV__ && invariant.error(78, error);
532
531
  }
533
532
  return;
534
533
  }
@@ -667,10 +666,6 @@ export class ObservableQuery {
667
666
  // TODO Make sure we update the networkStatus (and infer fetchVariables)
668
667
  // before actually committing to the fetch.
669
668
  const initialFetchPolicy = this.options.fetchPolicy;
670
- const queryInfo = new QueryInfo({
671
- queryManager: this.queryManager,
672
- observableQuery: this,
673
- });
674
669
  options.context ??= {};
675
670
  let synchronouslyEmitted = false;
676
671
  const onCacheHit = () => {
@@ -716,7 +711,13 @@ export class ObservableQuery {
716
711
  }
717
712
  }
718
713
  });
719
- let { observable, fromLink } = this.queryManager.fetchObservableWithInfo(queryInfo, options, { networkStatus, query: fetchQuery, onCacheHit, fetchQueryOperator });
714
+ let { observable, fromLink } = this.queryManager.fetchObservableWithInfo(options, {
715
+ networkStatus,
716
+ query: fetchQuery,
717
+ onCacheHit,
718
+ fetchQueryOperator,
719
+ observableQuery: this,
720
+ });
720
721
  // track query and variables from the start of the operation
721
722
  const { query, variables } = this;
722
723
  const operation = {
@@ -772,7 +773,7 @@ export class ObservableQuery {
772
773
  if (pollingInfo && pollingInfo.interval === pollInterval) {
773
774
  return;
774
775
  }
775
- invariant(pollInterval, 80);
776
+ invariant(pollInterval, 79);
776
777
  const info = pollingInfo || (this.pollingInfo = {});
777
778
  info.interval = pollInterval;
778
779
  const maybeFetch = () => {
@@ -1108,6 +1109,9 @@ export class ObservableQuery {
1108
1109
  };
1109
1110
  }
1110
1111
  calculateNetworkStatus(baseNetworkStatus) {
1112
+ if (baseNetworkStatus === NetworkStatus.streaming) {
1113
+ return baseNetworkStatus;
1114
+ }
1111
1115
  // in the future, this could be more complex logic, e.g. "refetch" and
1112
1116
  // "fetchMore" having priority over "polling" or "loading" network statuses
1113
1117
  // as for now we just take the "latest" operation that is still active,
@@ -1255,7 +1259,7 @@ export class ObservableQuery {
1255
1259
  }
1256
1260
  export function logMissingFieldErrors(missing) {
1257
1261
  if (__DEV__ && missing) {
1258
- __DEV__ && invariant.debug(81, missing);
1262
+ __DEV__ && invariant.debug(80, missing);
1259
1263
  }
1260
1264
  }
1261
1265
  function isEqualQuery(a, b) {