@apollo/client 4.1.0-alpha.7 → 4.1.0-alpha.9

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 (130) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/__cjs/cache/core/cache.cjs +64 -24
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +47 -0
  5. package/__cjs/cache/core/types/Cache.d.cts +38 -0
  6. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  7. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  8. package/__cjs/cache/inmemory/inMemoryCache.cjs +47 -0
  9. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  10. package/__cjs/cache/inmemory/inMemoryCache.d.cts +47 -0
  11. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  12. package/__cjs/cache/inmemory/policies.cjs +14 -5
  13. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  14. package/__cjs/cache/inmemory/policies.d.cts +5 -0
  15. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  16. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  17. package/__cjs/cache/inmemory/types.d.cts +1 -0
  18. package/__cjs/cache/inmemory/writeToStore.cjs +6 -5
  19. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  20. package/__cjs/cache/inmemory/writeToStore.d.cts +2 -1
  21. package/__cjs/core/ApolloClient.cjs +14 -14
  22. package/__cjs/core/ApolloClient.cjs.map +1 -1
  23. package/__cjs/core/ApolloClient.d.cts +21 -1
  24. package/__cjs/core/ObservableQuery.cjs +22 -8
  25. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  26. package/__cjs/core/ObservableQuery.d.cts +1 -0
  27. package/__cjs/core/QueryInfo.cjs +3 -0
  28. package/__cjs/core/QueryInfo.cjs.map +1 -1
  29. package/__cjs/core/QueryManager.cjs +27 -17
  30. package/__cjs/core/QueryManager.cjs.map +1 -1
  31. package/__cjs/core/QueryManager.d.cts +18 -2
  32. package/__cjs/invariantErrorCodes.cjs +39 -33
  33. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +13 -1
  34. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
  35. package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +1 -1
  36. package/__cjs/link/error/index.cjs +1 -1
  37. package/__cjs/link/error/index.cjs.map +1 -1
  38. package/__cjs/link/error/index.d.cts +1 -1
  39. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  40. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  41. package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
  42. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  43. package/__cjs/react/hooks/useQuery.cjs +7 -4
  44. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  45. package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -0
  46. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  47. package/__cjs/utilities/internal/checkDocument.cjs +2 -4
  48. package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
  49. package/__cjs/utilities/internal/constants.cjs +21 -0
  50. package/__cjs/utilities/internal/constants.cjs.map +1 -0
  51. package/__cjs/utilities/internal/constants.d.cts +18 -0
  52. package/__cjs/utilities/internal/index.cjs +6 -1
  53. package/__cjs/utilities/internal/index.cjs.map +1 -1
  54. package/__cjs/utilities/internal/index.d.cts +2 -0
  55. package/__cjs/utilities/internal/mapObservableFragment.cjs +27 -0
  56. package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -0
  57. package/__cjs/utilities/internal/mapObservableFragment.d.cts +3 -0
  58. package/__cjs/utilities/internal/memoize.cjs +31 -0
  59. package/__cjs/utilities/internal/memoize.cjs.map +1 -0
  60. package/__cjs/utilities/internal/memoize.d.cts +8 -0
  61. package/__cjs/version.cjs +1 -1
  62. package/cache/core/cache.d.ts +47 -0
  63. package/cache/core/cache.js +65 -25
  64. package/cache/core/cache.js.map +1 -1
  65. package/cache/core/types/Cache.d.ts +38 -0
  66. package/cache/core/types/Cache.js.map +1 -1
  67. package/cache/inmemory/entityStore.js +3 -3
  68. package/cache/inmemory/entityStore.js.map +1 -1
  69. package/cache/inmemory/inMemoryCache.d.ts +47 -0
  70. package/cache/inmemory/inMemoryCache.js +47 -0
  71. package/cache/inmemory/inMemoryCache.js.map +1 -1
  72. package/cache/inmemory/key-extractor.js +1 -1
  73. package/cache/inmemory/policies.d.ts +5 -0
  74. package/cache/inmemory/policies.js +14 -5
  75. package/cache/inmemory/policies.js.map +1 -1
  76. package/cache/inmemory/readFromStore.js +3 -3
  77. package/cache/inmemory/readFromStore.js.map +1 -1
  78. package/cache/inmemory/types.d.ts +1 -0
  79. package/cache/inmemory/types.js.map +1 -1
  80. package/cache/inmemory/writeToStore.d.ts +2 -1
  81. package/cache/inmemory/writeToStore.js +6 -5
  82. package/cache/inmemory/writeToStore.js.map +1 -1
  83. package/core/ApolloClient.d.ts +21 -1
  84. package/core/ApolloClient.js +15 -15
  85. package/core/ApolloClient.js.map +1 -1
  86. package/core/ObservableQuery.d.ts +1 -0
  87. package/core/ObservableQuery.js +23 -9
  88. package/core/ObservableQuery.js.map +1 -1
  89. package/core/QueryInfo.js +3 -0
  90. package/core/QueryInfo.js.map +1 -1
  91. package/core/QueryManager.d.ts +18 -2
  92. package/core/QueryManager.js +28 -18
  93. package/core/QueryManager.js.map +1 -1
  94. package/invariantErrorCodes.js +39 -33
  95. package/link/client-awareness/ClientAwarenessLink.d.ts +1 -1
  96. package/link/client-awareness/ClientAwarenessLink.js +13 -1
  97. package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
  98. package/link/error/index.d.ts +1 -1
  99. package/link/error/index.js +1 -1
  100. package/link/error/index.js.map +1 -1
  101. package/link/http/parseAndCheckHttpResponse.js +1 -1
  102. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  103. package/package.json +1 -1
  104. package/react/hooks/useLazyQuery.js +2 -1
  105. package/react/hooks/useLazyQuery.js.map +1 -1
  106. package/react/hooks/useQuery.js +8 -5
  107. package/react/hooks/useQuery.js.map +1 -1
  108. package/react/hooks/useSuspenseQuery.js +2 -0
  109. package/react/hooks/useSuspenseQuery.js.map +1 -1
  110. package/react/hooks-compiled/useLazyQuery.js +2 -1
  111. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  112. package/react/hooks-compiled/useQuery.js +9 -5
  113. package/react/hooks-compiled/useQuery.js.map +1 -1
  114. package/react/hooks-compiled/useSuspenseQuery.js +3 -1
  115. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  116. package/utilities/internal/checkDocument.js +2 -4
  117. package/utilities/internal/checkDocument.js.map +1 -1
  118. package/utilities/internal/constants.d.ts +18 -0
  119. package/utilities/internal/constants.js +18 -0
  120. package/utilities/internal/constants.js.map +1 -0
  121. package/utilities/internal/index.d.ts +2 -0
  122. package/utilities/internal/index.js +2 -0
  123. package/utilities/internal/index.js.map +1 -1
  124. package/utilities/internal/mapObservableFragment.d.ts +3 -0
  125. package/utilities/internal/mapObservableFragment.js +24 -0
  126. package/utilities/internal/mapObservableFragment.js.map +1 -0
  127. package/utilities/internal/memoize.d.ts +8 -0
  128. package/utilities/internal/memoize.js +28 -0
  129. package/utilities/internal/memoize.js.map +1 -0
  130. package/version.js +1 -1
@@ -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, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, } from "@apollo/client/utilities/internal";
5
+ import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
6
6
  import { invariant } from "@apollo/client/utilities/invariant";
7
7
  import { NetworkStatus } from "./networkStatus.js";
8
8
  const { assign, hasOwnProperty } = Object;
@@ -23,6 +23,7 @@ const empty = {
23
23
  export class ObservableQuery {
24
24
  options;
25
25
  queryName;
26
+ variablesUnknown = false;
26
27
  /**
27
28
  * @internal will be read and written from `QueryInfo`
28
29
  *
@@ -74,6 +75,10 @@ export class ObservableQuery {
74
75
  const { fetchPolicy = defaultFetchPolicy,
75
76
  // Make sure we don't store "standby" as the initialFetchPolicy.
76
77
  initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
78
+ if (options[variablesUnknownSymbol]) {
79
+ invariant(fetchPolicy === "standby", 80);
80
+ this.variablesUnknown = true;
81
+ }
77
82
  this.lastQuery = transformedQuery;
78
83
  this.options = {
79
84
  ...options,
@@ -375,7 +380,7 @@ export class ObservableQuery {
375
380
  const queryDef = getQueryDefinition(this.query);
376
381
  const vars = queryDef.variableDefinitions;
377
382
  if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
378
- __DEV__ && invariant.warn(80, variables, queryDef.name?.value || queryDef);
383
+ __DEV__ && invariant.warn(81, variables, queryDef.name?.value || queryDef);
379
384
  }
380
385
  }
381
386
  if (variables && !equal(this.variables, variables)) {
@@ -391,7 +396,7 @@ export class ObservableQuery {
391
396
  fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
392
397
  invariant(
393
398
  this.options.fetchPolicy !== "cache-only",
394
- 81,
399
+ 82,
395
400
  getOperationName(this.query, "(anonymous)")
396
401
  );
397
402
  const combinedOptions = {
@@ -425,7 +430,7 @@ export class ObservableQuery {
425
430
  let wasUpdated = false;
426
431
  const isCached = this.options.fetchPolicy !== "no-cache";
427
432
  if (!isCached) {
428
- invariant(updateQuery, 82);
433
+ invariant(updateQuery, 83);
429
434
  }
430
435
  const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
431
436
  pushNotification({
@@ -434,13 +439,14 @@ export class ObservableQuery {
434
439
  value: {},
435
440
  }, { shouldEmit: 3 /* EmitBehavior.networkStatusChange */ });
436
441
  const { promise, operator } = getTrackingOperatorPromise();
437
- const { observable } = this.queryManager.fetchObservableWithInfo(combinedOptions, { networkStatus: NetworkStatus.fetchMore });
442
+ const { observable } = this.queryManager.fetchObservableWithInfo(combinedOptions, { networkStatus: NetworkStatus.fetchMore, exposeExtensions: true });
438
443
  const subscription = observable
439
444
  .pipe(operator, filter((notification) => notification.kind === "N" && notification.source === "network"))
440
445
  .subscribe({
441
446
  next: (notification) => {
442
447
  wasUpdated = false;
443
448
  const fetchMoreResult = notification.value;
449
+ const extensions = fetchMoreResult[extensionsSymbol];
444
450
  if (isNetworkRequestSettled(notification.value.networkStatus)) {
445
451
  finalize();
446
452
  }
@@ -461,6 +467,7 @@ export class ObservableQuery {
461
467
  variables: this.variables,
462
468
  returnPartialData: true,
463
469
  optimistic: false,
470
+ extensions,
464
471
  }, (previous) => updateQuery(previous, {
465
472
  fetchMoreResult: fetchMoreResult.data,
466
473
  variables: combinedOptions.variables,
@@ -476,6 +483,7 @@ export class ObservableQuery {
476
483
  query: combinedOptions.query,
477
484
  variables: combinedOptions.variables,
478
485
  data: fetchMoreResult.data,
486
+ extensions,
479
487
  });
480
488
  }
481
489
  },
@@ -598,7 +606,7 @@ export class ObservableQuery {
598
606
  onError(error);
599
607
  }
600
608
  else {
601
- invariant.error(83, error);
609
+ invariant.error(84, error);
602
610
  }
603
611
  return;
604
612
  }
@@ -842,7 +850,7 @@ export class ObservableQuery {
842
850
  if (!this.didWarnCacheOnlyPolling &&
843
851
  pollInterval &&
844
852
  fetchPolicy === "cache-only") {
845
- __DEV__ && invariant.warn(84, getOperationName(this.query, "(anonymous)"));
853
+ __DEV__ && invariant.warn(85, getOperationName(this.query, "(anonymous)"));
846
854
  this.didWarnCacheOnlyPolling = true;
847
855
  }
848
856
  }
@@ -917,6 +925,10 @@ export class ObservableQuery {
917
925
  const oldVariables = this.variables;
918
926
  const oldFetchPolicy = this.options.fetchPolicy;
919
927
  const mergedOptions = compact(this.options, newOptions || {});
928
+ // This request will hit the network, so even if there are no variables,
929
+ // we now know that's intentional. (see #12996)
930
+ // Even if that happens only once, we want `variablesUnknown` to stay false permanently.
931
+ this.variablesUnknown &&= mergedOptions.fetchPolicy === "standby";
920
932
  const options = useDisposableObservable ?
921
933
  // Disposable Observable fetches receive a shallow copy of this.options
922
934
  // (merged with newOptions), leaving this.options unmodified.
@@ -1186,7 +1198,9 @@ export class ObservableQuery {
1186
1198
  // "fetchMore" having priority over "polling" or "loading" network statuses
1187
1199
  // as for now we just take the "latest" operation that is still active,
1188
1200
  // as that lines up best with previous behavior[]
1189
- const operation = Array.from(this.activeOperations.values()).findLast((operation) => isEqualQuery(operation, this) && operation.override !== undefined);
1201
+ const operation = Array.from(this.activeOperations.values())
1202
+ .reverse()
1203
+ .find((operation) => isEqualQuery(operation, this) && operation.override !== undefined);
1190
1204
  return operation?.override ?? baseNetworkStatus;
1191
1205
  }
1192
1206
  abortActiveOperations() {
@@ -1330,7 +1344,7 @@ export class ObservableQuery {
1330
1344
  }
1331
1345
  export function logMissingFieldErrors(missing) {
1332
1346
  if (__DEV__ && missing) {
1333
- __DEV__ && invariant.debug(85, missing);
1347
+ __DEV__ && invariant.debug(86, missing);
1334
1348
  }
1335
1349
  }
1336
1350
  function isEqualQuery(a, b) {