@apollo/client 3.9.6 → 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 (62) 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 +20 -0
  5. package/apollo-client.cjs +78 -39
  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/LocalState.js +13 -13
  18. package/core/LocalState.js.map +1 -1
  19. package/core/QueryManager.js +7 -7
  20. package/core/QueryManager.js.map +1 -1
  21. package/core/core.cjs +24 -21
  22. package/core/core.cjs.map +1 -1
  23. package/core/core.cjs.native.js +24 -21
  24. package/core/watchQueryOptions.d.ts +3 -3
  25. package/dev/dev.cjs +1 -1
  26. package/dev/dev.cjs.map +1 -1
  27. package/dev/dev.cjs.native.js +1 -1
  28. package/link/http/http.cjs +11 -8
  29. package/link/http/http.cjs.map +1 -1
  30. package/link/http/http.cjs.native.js +11 -8
  31. package/link/http/parseAndCheckHttpResponse.js +11 -8
  32. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  33. package/package.json +24 -24
  34. package/react/hooks/hooks.cjs +27 -18
  35. package/react/hooks/hooks.cjs.map +1 -1
  36. package/react/hooks/hooks.cjs.native.js +27 -18
  37. package/react/hooks/internal/useRenderGuard.js +1 -1
  38. package/react/hooks/internal/useRenderGuard.js.map +1 -1
  39. package/react/hooks/useFragment.d.ts +1 -1
  40. package/react/hooks/useFragment.js +22 -14
  41. package/react/hooks/useFragment.js.map +1 -1
  42. package/react/internal/cache/QueryReference.d.ts +2 -2
  43. package/react/internal/cache/QueryReference.js.map +1 -1
  44. package/react/query-preloader/createQueryPreloader.d.ts +6 -6
  45. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  46. package/react/types/types.d.ts +3 -3
  47. package/react/types/types.documentation.d.ts +4 -4
  48. package/react/types/types.documentation.js.map +1 -1
  49. package/testing/internal/ObservableStream.js +3 -3
  50. package/testing/internal/ObservableStream.js.map +1 -1
  51. package/testing/internal/profile/profile.js +6 -6
  52. package/testing/internal/profile/profile.js.map +1 -1
  53. package/utilities/globals/globals.cjs +1 -1
  54. package/utilities/globals/globals.cjs.map +1 -1
  55. package/utilities/globals/globals.cjs.native.js +1 -1
  56. package/utilities/subscriptions/relay/relay.cjs +11 -8
  57. package/utilities/subscriptions/relay/relay.cjs.map +1 -1
  58. package/utilities/subscriptions/relay/relay.cjs.native.js +11 -8
  59. package/utilities/subscriptions/urql/urql.cjs +11 -8
  60. package/utilities/subscriptions/urql/urql.cjs.map +1 -1
  61. package/utilities/subscriptions/urql/urql.cjs.native.js +11 -8
  62. 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,25 @@
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
+
15
+ ## 3.9.7
16
+
17
+ ### Patch Changes
18
+
19
+ - [#11659](https://github.com/apollographql/apollo-client/pull/11659) [`652a61e`](https://github.com/apollographql/apollo-client/commit/652a61e96db0f0e27d0a22fafae1df388f3fdf36) Thanks [@phryneas](https://github.com/phryneas)! - Make `useRenderGuard` more resilient to changes in React internals.
20
+
21
+ - [#11594](https://github.com/apollographql/apollo-client/pull/11594) [`50b1097`](https://github.com/apollographql/apollo-client/commit/50b10970ca0efa290ae415ef801650327a89ab8e) Thanks [@alessbell](https://github.com/alessbell)! - Adds a fix for multipart subscriptions that terminate with payload: null
22
+
3
23
  ## 3.9.6
4
24
 
5
25
  ### 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.6";
34
+ var version = "3.10.0-alpha.1";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -1938,10 +1938,10 @@ var ApolloError = (function (_super) {
1938
1938
 
1939
1939
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1940
1940
  function readMultipartBody(response, nextValue) {
1941
- var _a;
1942
1941
  return tslib.__awaiter(this, void 0, void 0, function () {
1943
- var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
1944
- var _c, _d;
1942
+ var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _a, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
1943
+ var _b, _c;
1944
+ var _d;
1945
1945
  return tslib.__generator(this, function (_e) {
1946
1946
  switch (_e.label) {
1947
1947
  case 0:
@@ -1949,7 +1949,7 @@ function readMultipartBody(response, nextValue) {
1949
1949
  throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
1950
1950
  }
1951
1951
  decoder = new TextDecoder("utf-8");
1952
- contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
1952
+ contentType = (_d = response.headers) === null || _d === void 0 ? void 0 : _d.get("content-type");
1953
1953
  delimiter = "boundary=";
1954
1954
  boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter)) ?
1955
1955
  contentType === null || contentType === void 0 ? void 0 : contentType.substring((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(delimiter)) + delimiter.length).replace(/['"]/g, "").replace(/\;(.*)/gm, "").trim()
@@ -1963,7 +1963,7 @@ function readMultipartBody(response, nextValue) {
1963
1963
  if (!running) return [3 , 3];
1964
1964
  return [4 , iterator.next()];
1965
1965
  case 2:
1966
- _b = _e.sent(), value = _b.value, done = _b.done;
1966
+ _a = _e.sent(), value = _a.value, done = _a.done;
1967
1967
  chunk = typeof value === "string" ? value : decoder.decode(value);
1968
1968
  searchFrom = buffer.length - boundary.length + 1;
1969
1969
  running = !done;
@@ -1971,10 +1971,10 @@ function readMultipartBody(response, nextValue) {
1971
1971
  bi = buffer.indexOf(boundary, searchFrom);
1972
1972
  while (bi > -1) {
1973
1973
  message = void 0;
1974
- _c = [
1974
+ _b = [
1975
1975
  buffer.slice(0, bi),
1976
1976
  buffer.slice(bi + boundary.length),
1977
- ], message = _c[0], buffer = _c[1];
1977
+ ], message = _b[0], buffer = _b[1];
1978
1978
  i = message.indexOf("\r\n\r\n");
1979
1979
  headers = parseHeaders(message.slice(0, i));
1980
1980
  contentType_1 = headers["content-type"];
@@ -1993,10 +1993,13 @@ function readMultipartBody(response, nextValue) {
1993
1993
  if (isApolloPayloadResult(result)) {
1994
1994
  next = {};
1995
1995
  if ("payload" in result) {
1996
+ if (Object.keys(result).length === 1 && result.payload === null) {
1997
+ return [2 ];
1998
+ }
1996
1999
  next = tslib.__assign({}, result.payload);
1997
2000
  }
1998
2001
  if ("errors" in result) {
1999
- next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
2002
+ next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_c = {}, _c[PROTOCOL_ERRORS_SYMBOL] = result.errors, _c)) });
2000
2003
  }
2001
2004
  nextValue(next);
2002
2005
  }
@@ -2413,6 +2416,33 @@ var ApolloCache = (function () {
2413
2416
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
2414
2417
  return this.read(tslib.__assign(tslib.__assign({}, options), { rootId: options.id || "ROOT_QUERY", optimistic: optimistic }));
2415
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
+ };
2416
2446
  ApolloCache.prototype.readFragment = function (options, optimistic) {
2417
2447
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
2418
2448
  return this.read(tslib.__assign(tslib.__assign({}, options), { query: this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
@@ -5436,9 +5466,9 @@ var LocalState = (function () {
5436
5466
  return this.resolvers || {};
5437
5467
  };
5438
5468
  LocalState.prototype.runResolvers = function (_a) {
5439
- var document = _a.document, remoteResult = _a.remoteResult, context = _a.context, variables = _a.variables, _b = _a.onlyRunForcedResolvers, onlyRunForcedResolvers = _b === void 0 ? false : _b;
5440
- return tslib.__awaiter(this, void 0, void 0, function () {
5441
- return tslib.__generator(this, function (_c) {
5469
+ return tslib.__awaiter(this, arguments, void 0, function (_b) {
5470
+ var document = _b.document, remoteResult = _b.remoteResult, context = _b.context, variables = _b.variables, _c = _b.onlyRunForcedResolvers, onlyRunForcedResolvers = _c === void 0 ? false : _c;
5471
+ return tslib.__generator(this, function (_d) {
5442
5472
  if (document) {
5443
5473
  return [2 , this.resolveDocument(document, remoteResult.data, context, variables, this.fragmentMatcher, onlyRunForcedResolvers).then(function (localResult) { return (tslib.__assign(tslib.__assign({}, remoteResult), { data: localResult.result })); })];
5444
5474
  }
@@ -5470,10 +5500,10 @@ var LocalState = (function () {
5470
5500
  return cache.identify(obj);
5471
5501
  } });
5472
5502
  };
5473
- LocalState.prototype.addExportedVariables = function (document, variables, context) {
5474
- if (variables === void 0) { variables = {}; }
5475
- if (context === void 0) { context = {}; }
5476
- return tslib.__awaiter(this, void 0, void 0, function () {
5503
+ LocalState.prototype.addExportedVariables = function (document_1) {
5504
+ return tslib.__awaiter(this, arguments, void 0, function (document, variables, context) {
5505
+ if (variables === void 0) { variables = {}; }
5506
+ if (context === void 0) { context = {}; }
5477
5507
  return tslib.__generator(this, function (_a) {
5478
5508
  if (document) {
5479
5509
  return [2 , this.resolveDocument(document, this.buildRootValueFromCache(document, variables) || {}, this.prepareContext(context), variables).then(function (data) { return (tslib.__assign(tslib.__assign({}, variables), data.exportedVariables)); })];
@@ -5510,13 +5540,13 @@ var LocalState = (function () {
5510
5540
  optimistic: false,
5511
5541
  }).result;
5512
5542
  };
5513
- LocalState.prototype.resolveDocument = function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
5514
- if (context === void 0) { context = {}; }
5515
- if (variables === void 0) { variables = {}; }
5516
- if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
5517
- if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
5518
- return tslib.__awaiter(this, void 0, void 0, function () {
5543
+ LocalState.prototype.resolveDocument = function (document_1, rootValue_1) {
5544
+ return tslib.__awaiter(this, arguments, void 0, function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
5519
5545
  var mainDefinition, fragments, fragmentMap, selectionsToResolve, definitionOperation, defaultOperationType, _a, cache, client, execContext, isClientFieldDescendant;
5546
+ if (context === void 0) { context = {}; }
5547
+ if (variables === void 0) { variables = {}; }
5548
+ if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
5549
+ if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
5520
5550
  return tslib.__generator(this, function (_b) {
5521
5551
  mainDefinition = getMainDefinition(document);
5522
5552
  fragments = getFragmentDefinitions(document);
@@ -6044,12 +6074,12 @@ var QueryManager = (function () {
6044
6074
  this.fetchCancelFns.clear();
6045
6075
  };
6046
6076
  QueryManager.prototype.mutate = function (_a) {
6047
- var _b, _c;
6048
- var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
6049
- return tslib.__awaiter(this, void 0, void 0, function () {
6077
+ return tslib.__awaiter(this, arguments, void 0, function (_b) {
6050
6078
  var mutationId, hasClientExports, mutationStoreValue, isOptimistic, self;
6051
- return tslib.__generator(this, function (_h) {
6052
- switch (_h.label) {
6079
+ var _c, _d;
6080
+ var mutation = _b.mutation, variables = _b.variables, optimisticResponse = _b.optimisticResponse, updateQueries = _b.updateQueries, _e = _b.refetchQueries, refetchQueries = _e === void 0 ? [] : _e, _f = _b.awaitRefetchQueries, awaitRefetchQueries = _f === void 0 ? false : _f, updateWithProxyFn = _b.update, onQueryUpdated = _b.onQueryUpdated, _g = _b.fetchPolicy, fetchPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.fetchPolicy) || "network-only" : _g, _h = _b.errorPolicy, errorPolicy = _h === void 0 ? ((_d = this.defaultOptions.mutate) === null || _d === void 0 ? void 0 : _d.errorPolicy) || "none" : _h, keepRootFields = _b.keepRootFields, context = _b.context;
6081
+ return tslib.__generator(this, function (_j) {
6082
+ switch (_j.label) {
6053
6083
  case 0:
6054
6084
  invariant(mutation, 26);
6055
6085
  invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 27);
@@ -6060,8 +6090,8 @@ var QueryManager = (function () {
6060
6090
  if (!hasClientExports) return [3 , 2];
6061
6091
  return [4 , this.localState.addExportedVariables(mutation, variables, context)];
6062
6092
  case 1:
6063
- variables = (_h.sent());
6064
- _h.label = 2;
6093
+ variables = (_j.sent());
6094
+ _j.label = 2;
6065
6095
  case 2:
6066
6096
  mutationStoreValue = this.mutationStore &&
6067
6097
  (this.mutationStore[mutationId] = {
@@ -7058,6 +7088,9 @@ var ApolloClient = (function () {
7058
7088
  if (optimistic === void 0) { optimistic = false; }
7059
7089
  return this.cache.readQuery(options, optimistic);
7060
7090
  };
7091
+ ApolloClient.prototype.watchFragment = function (options) {
7092
+ return this.cache.watchFragment(options);
7093
+ };
7061
7094
  ApolloClient.prototype.readFragment = function (options, optimistic) {
7062
7095
  if (optimistic === void 0) { optimistic = false; }
7063
7096
  return this.cache.readFragment(options, optimistic);
@@ -7387,7 +7420,7 @@ var RenderDispatcher = null;
7387
7420
  function useRenderGuard() {
7388
7421
  RenderDispatcher = getRenderDispatcher();
7389
7422
  return React__namespace.useCallback(function () {
7390
- return (RenderDispatcher !== null && RenderDispatcher === getRenderDispatcher());
7423
+ return (RenderDispatcher != null && RenderDispatcher === getRenderDispatcher());
7391
7424
  }, []);
7392
7425
  }
7393
7426
 
@@ -8045,21 +8078,27 @@ function _useFragment(options) {
8045
8078
  var resultRef = useLazyRef(function () {
8046
8079
  return diffToResult(cache.diff(diffOptions));
8047
8080
  });
8081
+ var stableOptions = useDeepMemo(function () { return options; }, [options]);
8082
+ React__namespace.useMemo(function () {
8083
+ resultRef.current = diffToResult(cache.diff(diffOptions));
8084
+ }, [diffOptions, cache]);
8048
8085
  var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
8049
8086
  return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
8050
8087
  var lastTimeout = 0;
8051
- var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
8052
- if (!equal.equal(diff.result, resultRef.current.data)) {
8053
- resultRef.current = diffToResult(diff);
8054
- clearTimeout(lastTimeout);
8055
- lastTimeout = setTimeout(forceUpdate);
8056
- }
8057
- } }));
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
+ });
8058
8097
  return function () {
8059
- unsubscribe();
8098
+ subscription.unsubscribe();
8060
8099
  clearTimeout(lastTimeout);
8061
8100
  };
8062
- }, [cache, diffOptions]), getSnapshot, getSnapshot);
8101
+ }, [cache, stableOptions]), getSnapshot, getSnapshot);
8063
8102
  }
8064
8103
  function diffToResult(diff) {
8065
8104
  var result = {