@apollo/client 3.9.10 → 3.10.0-rc.0

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 (65) hide show
  1. package/.changeset/chatty-llamas-switch.md +5 -0
  2. package/.changeset/pre.json +14 -0
  3. package/.changeset/stupid-bears-cheat.md +5 -0
  4. package/.changeset/tasty-pillows-ring.md +5 -0
  5. package/.changeset/tiny-bugs-tap.md +5 -0
  6. package/.changeset/twelve-apples-vanish.md +5 -0
  7. package/CHANGELOG.md +18 -0
  8. package/apollo-client.cjs +43 -10
  9. package/apollo-client.cjs.map +1 -1
  10. package/apollo-client.min.cjs +1 -1
  11. package/cache/cache.cjs +27 -0
  12. package/cache/cache.cjs.map +1 -1
  13. package/cache/cache.cjs.native.js +27 -0
  14. package/cache/core/cache.d.ts +83 -1
  15. package/cache/core/cache.js +30 -1
  16. package/cache/core/cache.js.map +1 -1
  17. package/core/ApolloClient.d.ts +19 -1
  18. package/core/ApolloClient.js +20 -1
  19. package/core/ApolloClient.js.map +1 -1
  20. package/core/core.cjs +4 -1
  21. package/core/core.cjs.map +1 -1
  22. package/core/core.cjs.native.js +4 -1
  23. package/dev/dev.cjs +1 -1
  24. package/dev/dev.cjs.map +1 -1
  25. package/dev/dev.cjs.native.js +1 -1
  26. package/package.json +2 -1
  27. package/react/hooks/hooks.cjs +23 -17
  28. package/react/hooks/hooks.cjs.map +1 -1
  29. package/react/hooks/hooks.cjs.native.js +23 -17
  30. package/react/hooks/useFragment.js +17 -14
  31. package/react/hooks/useFragment.js.map +1 -1
  32. package/react/internal/cache/QueryReference.d.ts +1 -1
  33. package/react/internal/cache/QueryReference.js.map +1 -1
  34. package/react/query-preloader/createQueryPreloader.d.ts +0 -1
  35. package/react/query-preloader/createQueryPreloader.js +0 -1
  36. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  37. package/react/react.cjs.map +1 -1
  38. package/testing/core/core.cjs +103 -0
  39. package/testing/core/core.cjs.map +1 -1
  40. package/testing/core/core.cjs.native.js +103 -0
  41. package/testing/core/createMockFetch.d.ts +38 -0
  42. package/testing/core/createMockFetch.js +79 -0
  43. package/testing/core/createMockFetch.js.map +1 -0
  44. package/testing/core/createProxiedSchema.d.ts +47 -0
  45. package/testing/core/createProxiedSchema.js +99 -0
  46. package/testing/core/createProxiedSchema.js.map +1 -0
  47. package/testing/core/index.d.ts +2 -0
  48. package/testing/core/index.js +2 -0
  49. package/testing/core/index.js.map +1 -1
  50. package/testing/graphql-tools/utils.d.ts +26 -0
  51. package/testing/graphql-tools/utils.js +172 -0
  52. package/testing/graphql-tools/utils.js.map +1 -0
  53. package/testing/graphql-tools/utils.test.d.ts +2 -0
  54. package/testing/graphql-tools/utils.test.js +139 -0
  55. package/testing/graphql-tools/utils.test.js.map +1 -0
  56. package/testing/index.d.ts +1 -0
  57. package/testing/index.js +1 -0
  58. package/testing/index.js.map +1 -1
  59. package/testing/testing.cjs +134 -0
  60. package/testing/testing.cjs.map +1 -1
  61. package/testing/testing.cjs.native.js +134 -0
  62. package/utilities/globals/globals.cjs +1 -1
  63. package/utilities/globals/globals.cjs.map +1 -1
  64. package/utilities/globals/globals.cjs.native.js +1 -1
  65. package/version.js +1 -1
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Adds `createMockFetch` utility for integration testing that includes the link chain
@@ -0,0 +1,14 @@
1
+ {
2
+ "mode": "pre",
3
+ "tag": "rc",
4
+ "initialVersions": {
5
+ "@apollo/client": "3.9.7"
6
+ },
7
+ "changesets": [
8
+ "chatty-llamas-switch",
9
+ "stupid-bears-cheat",
10
+ "tasty-pillows-ring",
11
+ "tiny-bugs-tap",
12
+ "twelve-apples-vanish"
13
+ ]
14
+ }
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Adds proxiedSchema and createMockSchema testing utilities
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Add `watchFragment` method to the cache and expose it on ApolloClient, refactor `useFragment` using `watchFragment`.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Remove alpha designation for `queryRef.toPromise()` to stabilize the API.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Remove alpha designation for `createQueryPreloader` to stabilize the API.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.10.0-rc.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#11605](https://github.com/apollographql/apollo-client/pull/11605) [`e2dd4c9`](https://github.com/apollographql/apollo-client/commit/e2dd4c95290cea604b548cc446826d89aafe8e11) Thanks [@alessbell](https://github.com/alessbell)! - Adds `createMockFetch` utility for integration testing that includes the link chain
8
+
9
+ - [#11605](https://github.com/apollographql/apollo-client/pull/11605) [`e2dd4c9`](https://github.com/apollographql/apollo-client/commit/e2dd4c95290cea604b548cc446826d89aafe8e11) Thanks [@alessbell](https://github.com/alessbell)! - Adds proxiedSchema and createMockSchema testing utilities
10
+
11
+ - [#11743](https://github.com/apollographql/apollo-client/pull/11743) [`78891f9`](https://github.com/apollographql/apollo-client/commit/78891f9ec81c0b7a7e010f5550a91965fa33a958) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove alpha designation for `queryRef.toPromise()` to stabilize the API.
12
+
13
+ - [#11743](https://github.com/apollographql/apollo-client/pull/11743) [`78891f9`](https://github.com/apollographql/apollo-client/commit/78891f9ec81c0b7a7e010f5550a91965fa33a958) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove alpha designation for `createQueryPreloader` to stabilize the API.
14
+
15
+ ## 3.10.0-alpha.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#11465](https://github.com/apollographql/apollo-client/pull/11465) [`7623da7`](https://github.com/apollographql/apollo-client/commit/7623da7720855b0c19e13ff9124679f426a39725) Thanks [@alessbell](https://github.com/alessbell)! - Add `watchFragment` method to the cache and expose it on ApolloClient, refactor `useFragment` using `watchFragment`.
20
+
3
21
  ## 3.9.10
4
22
 
5
23
  ### Patch Changes
package/apollo-client.cjs CHANGED
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
32
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
33
 
34
- var version = "3.9.10";
34
+ var version = "3.10.0-rc.0";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -2416,6 +2416,33 @@ var ApolloCache = (function () {
2416
2416
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
2417
2417
  return this.read(tslib.__assign(tslib.__assign({}, options), { rootId: options.id || "ROOT_QUERY", optimistic: optimistic }));
2418
2418
  };
2419
+ ApolloCache.prototype.watchFragment = function (options) {
2420
+ var _this = this;
2421
+ var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a;
2422
+ var diffOptions = {
2423
+ returnPartialData: true,
2424
+ id: typeof from === "string" ? from : this.identify(from),
2425
+ query: this.getFragmentDoc(fragment, fragmentName),
2426
+ optimistic: optimistic,
2427
+ };
2428
+ var latestDiff;
2429
+ return new zenObservableTs.Observable(function (observer) {
2430
+ return _this.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, query: _this.getFragmentDoc(fragment, fragmentName), callback: function (diff) {
2431
+ if (equal.equal(diff, latestDiff)) {
2432
+ return;
2433
+ }
2434
+ var result = {
2435
+ data: diff.result,
2436
+ complete: !!diff.complete,
2437
+ };
2438
+ if (diff.missing) {
2439
+ result.missing = mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
2440
+ }
2441
+ latestDiff = diff;
2442
+ observer.next(result);
2443
+ } }));
2444
+ });
2445
+ };
2419
2446
  ApolloCache.prototype.readFragment = function (options, optimistic) {
2420
2447
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
2421
2448
  return this.read(tslib.__assign(tslib.__assign({}, options), { query: this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
@@ -7063,6 +7090,9 @@ var ApolloClient = (function () {
7063
7090
  if (optimistic === void 0) { optimistic = false; }
7064
7091
  return this.cache.readQuery(options, optimistic);
7065
7092
  };
7093
+ ApolloClient.prototype.watchFragment = function (options) {
7094
+ return this.cache.watchFragment(options);
7095
+ };
7066
7096
  ApolloClient.prototype.readFragment = function (options, optimistic) {
7067
7097
  if (optimistic === void 0) { optimistic = false; }
7068
7098
  return this.cache.readFragment(options, optimistic);
@@ -8050,24 +8080,27 @@ function _useFragment(options) {
8050
8080
  var resultRef = useLazyRef(function () {
8051
8081
  return diffToResult(cache.diff(diffOptions));
8052
8082
  });
8083
+ var stableOptions = useDeepMemo(function () { return options; }, [options]);
8053
8084
  React__namespace.useMemo(function () {
8054
8085
  resultRef.current = diffToResult(cache.diff(diffOptions));
8055
8086
  }, [diffOptions, cache]);
8056
8087
  var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
8057
8088
  return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
8058
8089
  var lastTimeout = 0;
8059
- var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
8060
- if (!equal.equal(diff.result, resultRef.current.data)) {
8061
- resultRef.current = diffToResult(diff);
8062
- clearTimeout(lastTimeout);
8063
- lastTimeout = setTimeout(forceUpdate);
8064
- }
8065
- } }));
8090
+ var subscription = cache.watchFragment(stableOptions).subscribe({
8091
+ next: function (result) {
8092
+ if (equal__default(result, resultRef.current))
8093
+ return;
8094
+ resultRef.current = result;
8095
+ clearTimeout(lastTimeout);
8096
+ lastTimeout = setTimeout(forceUpdate);
8097
+ },
8098
+ });
8066
8099
  return function () {
8067
- unsubscribe();
8100
+ subscription.unsubscribe();
8068
8101
  clearTimeout(lastTimeout);
8069
8102
  };
8070
- }, [cache, diffOptions]), getSnapshot, getSnapshot);
8103
+ }, [cache, stableOptions]), getSnapshot, getSnapshot);
8071
8104
  }
8072
8105
  function diffToResult(diff) {
8073
8106
  var result = {