@apollo/client 3.9.7 → 3.10.0-alpha.1

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 (41) hide show
  1. package/.changeset/flat-singers-kiss.md +5 -0
  2. package/.changeset/pre.json +11 -0
  3. package/.changeset/tasty-pillows-ring.md +5 -0
  4. package/CHANGELOG.md +12 -0
  5. package/apollo-client.cjs +46 -10
  6. package/apollo-client.cjs.map +1 -1
  7. package/apollo-client.min.cjs +1 -1
  8. package/cache/cache.cjs +27 -0
  9. package/cache/cache.cjs.map +1 -1
  10. package/cache/cache.cjs.native.js +27 -0
  11. package/cache/core/cache.d.ts +83 -1
  12. package/cache/core/cache.js +30 -1
  13. package/cache/core/cache.js.map +1 -1
  14. package/core/ApolloClient.d.ts +26 -8
  15. package/core/ApolloClient.js +26 -7
  16. package/core/ApolloClient.js.map +1 -1
  17. package/core/core.cjs +4 -1
  18. package/core/core.cjs.map +1 -1
  19. package/core/core.cjs.native.js +4 -1
  20. package/core/watchQueryOptions.d.ts +3 -3
  21. package/dev/dev.cjs +1 -1
  22. package/dev/dev.cjs.map +1 -1
  23. package/dev/dev.cjs.native.js +1 -1
  24. package/package.json +17 -17
  25. package/react/hooks/hooks.cjs +26 -17
  26. package/react/hooks/hooks.cjs.map +1 -1
  27. package/react/hooks/hooks.cjs.native.js +26 -17
  28. package/react/hooks/useFragment.d.ts +1 -1
  29. package/react/hooks/useFragment.js +22 -14
  30. package/react/hooks/useFragment.js.map +1 -1
  31. package/react/internal/cache/QueryReference.d.ts +2 -2
  32. package/react/internal/cache/QueryReference.js.map +1 -1
  33. package/react/query-preloader/createQueryPreloader.d.ts +6 -6
  34. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  35. package/react/types/types.d.ts +3 -3
  36. package/react/types/types.documentation.d.ts +4 -4
  37. package/react/types/types.documentation.js.map +1 -1
  38. package/utilities/globals/globals.cjs +1 -1
  39. package/utilities/globals/globals.cjs.map +1 -1
  40. package/utilities/globals/globals.cjs.native.js +1 -1
  41. package/version.js +1 -1
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": patch
3
+ ---
4
+
5
+ Fix issue where passing a new `from` option to `useFragment` would first render with the previous value before rerendering with the correct value.
@@ -0,0 +1,11 @@
1
+ {
2
+ "mode": "pre",
3
+ "tag": "alpha",
4
+ "initialVersions": {
5
+ "@apollo/client": "3.9.7"
6
+ },
7
+ "changesets": [
8
+ "flat-singers-kiss",
9
+ "tasty-pillows-ring"
10
+ ]
11
+ }
@@ -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`.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.10.0-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#11689](https://github.com/apollographql/apollo-client/pull/11689) [`cb8ffe5`](https://github.com/apollographql/apollo-client/commit/cb8ffe50e903397f741b62a44624bfe69b5f7b75) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix issue where passing a new `from` option to `useFragment` would first render with the previous value before rerendering with the correct value.
8
+
9
+ ## 3.10.0-alpha.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#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`.
14
+
3
15
  ## 3.9.7
4
16
 
5
17
  ### 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.7";
34
+ var version = "3.10.0-alpha.1";
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 }));
@@ -7061,6 +7088,9 @@ var ApolloClient = (function () {
7061
7088
  if (optimistic === void 0) { optimistic = false; }
7062
7089
  return this.cache.readQuery(options, optimistic);
7063
7090
  };
7091
+ ApolloClient.prototype.watchFragment = function (options) {
7092
+ return this.cache.watchFragment(options);
7093
+ };
7064
7094
  ApolloClient.prototype.readFragment = function (options, optimistic) {
7065
7095
  if (optimistic === void 0) { optimistic = false; }
7066
7096
  return this.cache.readFragment(options, optimistic);
@@ -8048,21 +8078,27 @@ function _useFragment(options) {
8048
8078
  var resultRef = useLazyRef(function () {
8049
8079
  return diffToResult(cache.diff(diffOptions));
8050
8080
  });
8081
+ var stableOptions = useDeepMemo(function () { return options; }, [options]);
8082
+ React__namespace.useMemo(function () {
8083
+ resultRef.current = diffToResult(cache.diff(diffOptions));
8084
+ }, [diffOptions, cache]);
8051
8085
  var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
8052
8086
  return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
8053
8087
  var lastTimeout = 0;
8054
- var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
8055
- if (!equal.equal(diff.result, resultRef.current.data)) {
8056
- resultRef.current = diffToResult(diff);
8057
- clearTimeout(lastTimeout);
8058
- lastTimeout = setTimeout(forceUpdate);
8059
- }
8060
- } }));
8088
+ var subscription = cache.watchFragment(stableOptions).subscribe({
8089
+ next: function (result) {
8090
+ if (equal__default(result, resultRef.current))
8091
+ return;
8092
+ resultRef.current = result;
8093
+ clearTimeout(lastTimeout);
8094
+ lastTimeout = setTimeout(forceUpdate);
8095
+ },
8096
+ });
8061
8097
  return function () {
8062
- unsubscribe();
8098
+ subscription.unsubscribe();
8063
8099
  clearTimeout(lastTimeout);
8064
8100
  };
8065
- }, [cache, diffOptions]), getSnapshot, getSnapshot);
8101
+ }, [cache, stableOptions]), getSnapshot, getSnapshot);
8066
8102
  }
8067
8103
  function diffToResult(diff) {
8068
8104
  var result = {