@apollo/client 3.13.5 → 3.13.7

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.
@@ -10,6 +10,7 @@ var equal = require('@wry/equality');
10
10
  var utilities = require('../utilities');
11
11
  var cache = require('../cache');
12
12
  var errors = require('../errors');
13
+ var optimism = require('optimism');
13
14
  var trie = require('@wry/trie');
14
15
  var masking = require('../masking');
15
16
  var graphql = require('graphql');
@@ -21,7 +22,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
21
22
 
22
23
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
23
24
 
24
- var version = "3.13.5";
25
+ var version = "3.13.7";
25
26
 
26
27
  function isNonNullObject(obj) {
27
28
  return obj !== null && typeof obj === "object";
@@ -199,7 +200,13 @@ var ObservableQuery = (function (_super) {
199
200
  tslib.__extends(ObservableQuery, _super);
200
201
  function ObservableQuery(_a) {
201
202
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
202
- var _this = _super.call(this, function (observer) {
203
+ var _this = this;
204
+ var startedInactive = ObservableQuery.inactiveOnCreation.getValue();
205
+ _this = _super.call(this, function (observer) {
206
+ if (startedInactive) {
207
+ queryManager["queries"].set(_this.queryId, queryInfo);
208
+ startedInactive = false;
209
+ }
203
210
  try {
204
211
  var subObserver = observer._subscription._observer;
205
212
  if (subObserver && !subObserver.error) {
@@ -227,6 +234,7 @@ var ObservableQuery = (function (_super) {
227
234
  }) || this;
228
235
  _this.observers = new Set();
229
236
  _this.subscriptions = new Set();
237
+ _this.dirty = false;
230
238
  _this.queryInfo = queryInfo;
231
239
  _this.queryManager = queryManager;
232
240
  _this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy);
@@ -470,7 +478,7 @@ var ObservableQuery = (function (_super) {
470
478
  })
471
479
  .finally(function () {
472
480
  if (isCached && !updatedQuerySet.has(_this.query)) {
473
- reobserveCacheFirst(_this);
481
+ _this.reobserveCacheFirst();
474
482
  }
475
483
  });
476
484
  };
@@ -579,8 +587,9 @@ var ObservableQuery = (function (_super) {
579
587
  return options.fetchPolicy;
580
588
  };
581
589
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus, query) {
582
- this.queryManager.setObservableQuery(this);
583
- return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus, query);
590
+ var queryInfo = this.queryManager.getOrCreateQuery(this.queryId);
591
+ queryInfo.setObservableQuery(this);
592
+ return this.queryManager["fetchConcastWithInfo"](queryInfo, options, newNetworkStatus, query);
584
593
  };
585
594
  ObservableQuery.prototype.updatePolling = function () {
586
595
  var _this = this;
@@ -762,25 +771,62 @@ var ObservableQuery = (function (_super) {
762
771
  id: this.queryId,
763
772
  }) }) : result;
764
773
  };
774
+ ObservableQuery.prototype.resetNotifications = function () {
775
+ this.cancelNotifyTimeout();
776
+ this.dirty = false;
777
+ };
778
+ ObservableQuery.prototype.cancelNotifyTimeout = function () {
779
+ if (this.notifyTimeout) {
780
+ clearTimeout(this.notifyTimeout);
781
+ this.notifyTimeout = void 0;
782
+ }
783
+ };
784
+ ObservableQuery.prototype.scheduleNotify = function () {
785
+ var _this = this;
786
+ if (this.dirty)
787
+ return;
788
+ this.dirty = true;
789
+ if (!this.notifyTimeout) {
790
+ this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
791
+ }
792
+ };
793
+ ObservableQuery.prototype.notify = function () {
794
+ this.cancelNotifyTimeout();
795
+ if (this.dirty) {
796
+ if (this.options.fetchPolicy == "cache-only" ||
797
+ this.options.fetchPolicy == "cache-and-network" ||
798
+ !isNetworkRequestInFlight(this.queryInfo.networkStatus)) {
799
+ var diff = this.queryInfo.getDiff();
800
+ if (diff.fromOptimisticTransaction) {
801
+ this.observe();
802
+ }
803
+ else {
804
+ this.reobserveCacheFirst();
805
+ }
806
+ }
807
+ }
808
+ this.dirty = false;
809
+ };
810
+ ObservableQuery.prototype.reobserveCacheFirst = function () {
811
+ var _a = this.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
812
+ if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
813
+ return this.reobserve({
814
+ fetchPolicy: "cache-first",
815
+ nextFetchPolicy: function (currentFetchPolicy, context) {
816
+ this.nextFetchPolicy = nextFetchPolicy;
817
+ if (typeof this.nextFetchPolicy === "function") {
818
+ return this.nextFetchPolicy(currentFetchPolicy, context);
819
+ }
820
+ return fetchPolicy;
821
+ },
822
+ });
823
+ }
824
+ return this.reobserve();
825
+ };
826
+ ObservableQuery.inactiveOnCreation = new optimism.Slot();
765
827
  return ObservableQuery;
766
828
  }(utilities.Observable));
767
829
  utilities.fixObservableSubclass(ObservableQuery);
768
- function reobserveCacheFirst(obsQuery) {
769
- var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
770
- if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
771
- return obsQuery.reobserve({
772
- fetchPolicy: "cache-first",
773
- nextFetchPolicy: function (currentFetchPolicy, context) {
774
- this.nextFetchPolicy = nextFetchPolicy;
775
- if (typeof this.nextFetchPolicy === "function") {
776
- return this.nextFetchPolicy(currentFetchPolicy, context);
777
- }
778
- return fetchPolicy;
779
- },
780
- });
781
- }
782
- return obsQuery.reobserve();
783
- }
784
830
  function defaultSubscriptionObserverErrorCallback(error) {
785
831
  globalThis.__DEV__ !== false && globals.invariant.error(25, error.message, error.stack);
786
832
  }
@@ -806,21 +852,13 @@ function wrapDestructiveCacheMethod(cache, methodName) {
806
852
  };
807
853
  }
808
854
  }
809
- function cancelNotifyTimeout(info) {
810
- if (info["notifyTimeout"]) {
811
- clearTimeout(info["notifyTimeout"]);
812
- info["notifyTimeout"] = void 0;
813
- }
814
- }
815
855
  var QueryInfo = (function () {
816
856
  function QueryInfo(queryManager, queryId) {
817
857
  if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
818
858
  this.queryId = queryId;
819
- this.listeners = new Set();
820
859
  this.document = null;
821
860
  this.lastRequestId = 1;
822
861
  this.stopped = false;
823
- this.dirty = false;
824
862
  this.observableQuery = null;
825
863
  var cache = (this.cache = queryManager.cache);
826
864
  if (!destructiveMethodCounts.has(cache)) {
@@ -856,10 +894,6 @@ var QueryInfo = (function () {
856
894
  }
857
895
  return this;
858
896
  };
859
- QueryInfo.prototype.reset = function () {
860
- cancelNotifyTimeout(this);
861
- this.dirty = false;
862
- };
863
897
  QueryInfo.prototype.resetDiff = function () {
864
898
  this.lastDiff = void 0;
865
899
  };
@@ -898,68 +932,29 @@ var QueryInfo = (function () {
898
932
  };
899
933
  };
900
934
  QueryInfo.prototype.setDiff = function (diff) {
901
- var _this = this;
902
- var _a;
935
+ var _a, _b;
903
936
  var oldDiff = this.lastDiff && this.lastDiff.diff;
904
937
  if (diff && !diff.complete && ((_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.getLastError())) {
905
938
  return;
906
939
  }
907
940
  this.updateLastDiff(diff);
908
- if (!this.dirty && !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
909
- this.dirty = true;
910
- if (!this.notifyTimeout) {
911
- this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
912
- }
941
+ if (!equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
942
+ (_b = this.observableQuery) === null || _b === void 0 ? void 0 : _b["scheduleNotify"]();
913
943
  }
914
944
  };
915
945
  QueryInfo.prototype.setObservableQuery = function (oq) {
916
- var _this = this;
917
946
  if (oq === this.observableQuery)
918
947
  return;
919
- if (this.oqListener) {
920
- this.listeners.delete(this.oqListener);
921
- }
922
948
  this.observableQuery = oq;
923
949
  if (oq) {
924
950
  oq["queryInfo"] = this;
925
- this.listeners.add((this.oqListener = function () {
926
- var diff = _this.getDiff();
927
- if (diff.fromOptimisticTransaction) {
928
- oq["observe"]();
929
- }
930
- else {
931
- reobserveCacheFirst(oq);
932
- }
933
- }));
934
- }
935
- else {
936
- delete this.oqListener;
937
951
  }
938
952
  };
939
- QueryInfo.prototype.notify = function () {
940
- var _this = this;
941
- cancelNotifyTimeout(this);
942
- if (this.shouldNotify()) {
943
- this.listeners.forEach(function (listener) { return listener(_this); });
944
- }
945
- this.dirty = false;
946
- };
947
- QueryInfo.prototype.shouldNotify = function () {
948
- if (!this.dirty || !this.listeners.size) {
949
- return false;
950
- }
951
- if (isNetworkRequestInFlight(this.networkStatus) && this.observableQuery) {
952
- var fetchPolicy = this.observableQuery.options.fetchPolicy;
953
- if (fetchPolicy !== "cache-only" && fetchPolicy !== "cache-and-network") {
954
- return false;
955
- }
956
- }
957
- return true;
958
- };
959
953
  QueryInfo.prototype.stop = function () {
954
+ var _a;
960
955
  if (!this.stopped) {
961
956
  this.stopped = true;
962
- this.reset();
957
+ (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a["resetNotifications"]();
963
958
  this.cancel();
964
959
  var oq = this.observableQuery;
965
960
  if (oq)
@@ -996,9 +991,10 @@ var QueryInfo = (function () {
996
991
  };
997
992
  QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
998
993
  var _this = this;
994
+ var _a;
999
995
  var merger = new utilities.DeepMerger();
1000
996
  var graphQLErrors = utilities.isNonEmptyArray(result.errors) ? result.errors.slice(0) : [];
1001
- this.reset();
997
+ (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a["resetNotifications"]();
1002
998
  if ("incremental" in result && utilities.isNonEmptyArray(result.incremental)) {
1003
999
  var mergedData = utilities.mergeIncrementalData(this.getDiff().result, result);
1004
1000
  result.data = mergedData;
@@ -1054,9 +1050,10 @@ var QueryInfo = (function () {
1054
1050
  return (this.networkStatus = exports.NetworkStatus.ready);
1055
1051
  };
1056
1052
  QueryInfo.prototype.markError = function (error) {
1053
+ var _a;
1057
1054
  this.networkStatus = exports.NetworkStatus.error;
1058
1055
  this.lastWrite = void 0;
1059
- this.reset();
1056
+ (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a["resetNotifications"]();
1060
1057
  if (error.graphQLErrors) {
1061
1058
  this.graphQLErrors = error.graphQLErrors;
1062
1059
  }
@@ -1384,8 +1381,7 @@ var QueryManager = (function () {
1384
1381
  return true;
1385
1382
  };
1386
1383
  QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
1387
- return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
1388
- .promise;
1384
+ return this.fetchConcastWithInfo(this.getOrCreateQuery(queryId), options, networkStatus).concast.promise;
1389
1385
  };
1390
1386
  QueryManager.prototype.getQueryStore = function () {
1391
1387
  var store = Object.create(null);
@@ -1453,7 +1449,9 @@ var QueryManager = (function () {
1453
1449
  options: options,
1454
1450
  });
1455
1451
  observable["lastQuery"] = query;
1456
- this.queries.set(observable.queryId, queryInfo);
1452
+ if (!ObservableQuery["inactiveOnCreation"].getValue()) {
1453
+ this.queries.set(observable.queryId, queryInfo);
1454
+ }
1457
1455
  queryInfo.init({
1458
1456
  document: query,
1459
1457
  observableQuery: observable,
@@ -1565,7 +1563,7 @@ var QueryManager = (function () {
1565
1563
  if (legacyQueryOptions.size) {
1566
1564
  legacyQueryOptions.forEach(function (options) {
1567
1565
  var queryId = utilities.makeUniqueId("legacyOneTimeQuery");
1568
- var queryInfo = _this.getQuery(queryId).init({
1566
+ var queryInfo = _this.getOrCreateQuery(queryId).init({
1569
1567
  document: options.query,
1570
1568
  variables: options.variables,
1571
1569
  });
@@ -1605,14 +1603,11 @@ var QueryManager = (function () {
1605
1603
  (fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
1606
1604
  observableQueryPromises.push(observableQuery.refetch());
1607
1605
  }
1608
- _this.getQuery(queryId).setDiff(null);
1606
+ (_this.queries.get(queryId) || observableQuery["queryInfo"]).setDiff(null);
1609
1607
  });
1610
1608
  this.broadcastQueries();
1611
1609
  return Promise.all(observableQueryPromises);
1612
1610
  };
1613
- QueryManager.prototype.setObservableQuery = function (observableQuery) {
1614
- this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
1615
- };
1616
1611
  QueryManager.prototype.startGraphQLSubscription = function (options) {
1617
1612
  var _this = this;
1618
1613
  var query = options.query, variables = options.variables;
@@ -1673,16 +1668,17 @@ var QueryManager = (function () {
1673
1668
  this.removeQuery(queryId);
1674
1669
  };
1675
1670
  QueryManager.prototype.removeQuery = function (queryId) {
1671
+ var _a;
1676
1672
  this.fetchCancelFns.delete(queryId);
1677
1673
  if (this.queries.has(queryId)) {
1678
- this.getQuery(queryId).stop();
1674
+ (_a = this.queries.get(queryId)) === null || _a === void 0 ? void 0 : _a.stop();
1679
1675
  this.queries.delete(queryId);
1680
1676
  }
1681
1677
  };
1682
1678
  QueryManager.prototype.broadcastQueries = function () {
1683
1679
  if (this.onBroadcast)
1684
1680
  this.onBroadcast();
1685
- this.queries.forEach(function (info) { return info.notify(); });
1681
+ this.queries.forEach(function (info) { var _a; return (_a = info.observableQuery) === null || _a === void 0 ? void 0 : _a["notify"](); });
1686
1682
  };
1687
1683
  QueryManager.prototype.getLocalState = function () {
1688
1684
  return this.localState;
@@ -1783,13 +1779,12 @@ var QueryManager = (function () {
1783
1779
  throw error;
1784
1780
  });
1785
1781
  };
1786
- QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
1782
+ QueryManager.prototype.fetchConcastWithInfo = function (queryInfo, options,
1787
1783
  networkStatus, query) {
1788
1784
  var _this = this;
1789
1785
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
1790
1786
  if (query === void 0) { query = options.query; }
1791
1787
  var variables = this.getVariables(query, options.variables);
1792
- var queryInfo = this.getQuery(queryId);
1793
1788
  var defaults = this.defaultOptions.watchQuery;
1794
1789
  var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? (defaults && defaults.fetchPolicy) || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? (defaults && defaults.errorPolicy) || "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
1795
1790
  var normalized = Object.assign({}, options, {
@@ -1812,8 +1807,8 @@ var QueryManager = (function () {
1812
1807
  }
1813
1808
  return sourcesWithInfo;
1814
1809
  };
1815
- var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
1816
- this.fetchCancelFns.set(queryId, function (reason) {
1810
+ var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryInfo.queryId); };
1811
+ this.fetchCancelFns.set(queryInfo.queryId, function (reason) {
1817
1812
  cleanupCancelFn();
1818
1813
  setTimeout(function () { return concast.cancel(reason); });
1819
1814
  });
@@ -1844,7 +1839,7 @@ var QueryManager = (function () {
1844
1839
  this.getObservableQueries(include).forEach(function (oq, queryId) {
1845
1840
  includedQueriesById.set(queryId, {
1846
1841
  oq: oq,
1847
- lastDiff: _this.getQuery(queryId).getDiff(),
1842
+ lastDiff: (_this.queries.get(queryId) || oq["queryInfo"]).getDiff(),
1848
1843
  });
1849
1844
  });
1850
1845
  }
@@ -1881,9 +1876,7 @@ var QueryManager = (function () {
1881
1876
  var result;
1882
1877
  if (onQueryUpdated) {
1883
1878
  if (!diff) {
1884
- var info = oq["queryInfo"];
1885
- info.reset();
1886
- diff = info.getDiff();
1879
+ diff = _this.cache.diff(oq["queryInfo"]["getDiffOptions"]());
1887
1880
  }
1888
1881
  result = onQueryUpdated(oq, diff, lastDiff);
1889
1882
  }
@@ -2040,7 +2033,7 @@ var QueryManager = (function () {
2040
2033
  return { fromLink: false, sources: [] };
2041
2034
  }
2042
2035
  };
2043
- QueryManager.prototype.getQuery = function (queryId) {
2036
+ QueryManager.prototype.getOrCreateQuery = function (queryId) {
2044
2037
  if (queryId && !this.queries.has(queryId)) {
2045
2038
  this.queries.set(queryId, new QueryInfo(this, queryId));
2046
2039
  }
package/core/types.d.ts CHANGED
@@ -2,7 +2,6 @@ import type { DocumentNode, GraphQLFormattedError } from "graphql";
2
2
  import type { ApolloCache } from "../cache/index.js";
3
3
  import type { FetchResult } from "../link/core/index.js";
4
4
  import type { ApolloError } from "../errors/index.js";
5
- import type { QueryInfo } from "./QueryInfo.js";
6
5
  import type { NetworkStatus } from "./networkStatus.js";
7
6
  import type { Resolver } from "./LocalState.js";
8
7
  import type { ObservableQuery } from "./ObservableQuery.js";
@@ -16,7 +15,6 @@ export type MethodKeys<T> = {
16
15
  }[keyof T];
17
16
  export interface DefaultContext extends Record<string, any> {
18
17
  }
19
- export type QueryListener = (queryInfo: QueryInfo) => void;
20
18
  export type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache.DiffResult<any>, lastDiff: Cache.DiffResult<any> | undefined) => boolean | TResult;
21
19
  export type RefetchQueryDescriptor = string | DocumentNode;
22
20
  export type InternalRefetchQueryDescriptor = RefetchQueryDescriptor | QueryOptions;
package/core/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, GraphQLFormattedError } from \"graphql\";\n\nimport type { ApolloCache } from \"../cache/index.js\";\nimport type { FetchResult } from \"../link/core/index.js\";\nimport type { ApolloError } from \"../errors/index.js\";\nimport type { QueryInfo } from \"./QueryInfo.js\";\nimport type { NetworkStatus } from \"./networkStatus.js\";\nimport type { Resolver } from \"./LocalState.js\";\nimport type { ObservableQuery } from \"./ObservableQuery.js\";\nimport type { QueryOptions } from \"./watchQueryOptions.js\";\nimport type { Cache } from \"../cache/index.js\";\nimport type { IsStrictlyAny } from \"../utilities/index.js\";\nimport type { Unmasked } from \"../masking/index.js\";\n\nexport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\n\nexport type MethodKeys<T> = {\n [P in keyof T]: T[P] extends Function ? P : never;\n}[keyof T];\n\nexport interface DefaultContext extends Record<string, any> {}\n\nexport type QueryListener = (queryInfo: QueryInfo) => void;\n\nexport type OnQueryUpdated<TResult> = (\n observableQuery: ObservableQuery<any>,\n diff: Cache.DiffResult<any>,\n lastDiff: Cache.DiffResult<any> | undefined\n) => boolean | TResult;\n\nexport type RefetchQueryDescriptor = string | DocumentNode;\nexport type InternalRefetchQueryDescriptor =\n | RefetchQueryDescriptor\n | QueryOptions;\n\ntype RefetchQueriesIncludeShorthand = \"all\" | \"active\";\n\nexport type RefetchQueriesInclude =\n | RefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\nexport type InternalRefetchQueriesInclude =\n | InternalRefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\n// Used by ApolloClient[\"refetchQueries\"]\n// TODO Improve documentation comments for this public type.\nexport interface RefetchQueriesOptions<\n TCache extends ApolloCache<any>,\n TResult,\n> {\n updateCache?: (cache: TCache) => void;\n // The client.refetchQueries method discourages passing QueryOptions, by\n // restricting the public type of options.include to exclude QueryOptions as\n // an available array element type (see InternalRefetchQueriesInclude for a\n // version of RefetchQueriesInclude that allows legacy QueryOptions objects).\n include?: RefetchQueriesInclude;\n optimistic?: boolean;\n // If no onQueryUpdated function is provided, any queries affected by the\n // updateCache function or included in the options.include array will be\n // refetched by default. Passing null instead of undefined disables this\n // default refetching behavior for affected queries, though included queries\n // will still be refetched.\n onQueryUpdated?: OnQueryUpdated<TResult> | null;\n}\n\n// The client.refetchQueries method returns a thenable (PromiseLike) object\n// whose result is an array of Promise.resolve'd TResult values, where TResult\n// is whatever type the (optional) onQueryUpdated function returns. When no\n// onQueryUpdated function is given, TResult defaults to ApolloQueryResult<any>\n// (thanks to default type parameters for client.refetchQueries).\nexport type RefetchQueriesPromiseResults<TResult> =\n // If onQueryUpdated returns any, all bets are off, so the results array must\n // be a generic any[] array, which is much less confusing than the union type\n // we get if we don't check for any. I hoped `any extends TResult` would do\n // the trick here, instead of IsStrictlyAny, but you can see for yourself what\n // fails in the refetchQueries tests if you try making that simplification.\n IsStrictlyAny<TResult> extends true ? any[]\n : // If the onQueryUpdated function passed to client.refetchQueries returns true\n // or false, that means either to refetch the query (true) or to skip the\n // query (false). Since refetching produces an ApolloQueryResult<any>, and\n // skipping produces nothing, the fully-resolved array of all results produced\n // will be an ApolloQueryResult<any>[], when TResult extends boolean.\n TResult extends boolean ? ApolloQueryResult<any>[]\n : // If onQueryUpdated returns a PromiseLike<U>, that thenable will be passed as\n // an array element to Promise.all, so we infer/unwrap the array type U here.\n TResult extends PromiseLike<infer U> ? U[]\n : // All other onQueryUpdated results end up in the final Promise.all array as\n // themselves, with their original TResult type. Note that TResult will\n // default to ApolloQueryResult<any> if no onQueryUpdated function is passed\n // to client.refetchQueries.\n TResult[];\n\n// The result of client.refetchQueries is thenable/awaitable, if you just want\n// an array of fully resolved results, but you can also access the raw results\n// immediately by examining the additional { queries, results } properties of\n// the RefetchQueriesResult<TResult> object.\nexport interface RefetchQueriesResult<TResult>\n extends Promise<RefetchQueriesPromiseResults<TResult>> {\n // An array of ObservableQuery objects corresponding 1:1 to TResult values\n // in the results arrays (both the TResult[] array below, and the results\n // array resolved by the Promise above).\n queries: ObservableQuery<any>[];\n // These are the raw TResult values returned by any onQueryUpdated functions\n // that were invoked by client.refetchQueries.\n results: InternalRefetchQueriesResult<TResult>[];\n}\n\n// Used by QueryManager[\"refetchQueries\"]\nexport interface InternalRefetchQueriesOptions<\n TCache extends ApolloCache<any>,\n TResult,\n> extends Omit<RefetchQueriesOptions<TCache, TResult>, \"include\"> {\n // Just like the refetchQueries option for a mutation, an array of strings,\n // DocumentNode objects, and/or QueryOptions objects, or one of the shorthand\n // strings \"all\" or \"active\", to select every (active) query.\n include?: InternalRefetchQueriesInclude;\n // This part of the API is a (useful) implementation detail, but need not be\n // exposed in the public client.refetchQueries API (above).\n removeOptimistic?: string;\n}\n\nexport type InternalRefetchQueriesResult<TResult> =\n // If onQueryUpdated returns a boolean, that's equivalent to refetching the\n // query when the boolean is true and skipping the query when false, so the\n // internal type of refetched results is Promise<ApolloQueryResult<any>>.\n TResult extends boolean ? Promise<ApolloQueryResult<any>>\n : // Otherwise, onQueryUpdated returns whatever it returns. If onQueryUpdated is\n // not provided, TResult defaults to Promise<ApolloQueryResult<any>> (see the\n // generic type parameters of client.refetchQueries).\n TResult;\n\nexport type InternalRefetchQueriesMap<TResult> = Map<\n ObservableQuery<any>,\n InternalRefetchQueriesResult<TResult>\n>;\n\n// TODO Remove this unnecessary type in Apollo Client 4.\nexport type { QueryOptions as PureQueryOptions };\n\nexport type OperationVariables = Record<string, any>;\n\nexport interface ApolloQueryResult<T> {\n data: T;\n /**\n * A list of any errors that occurred during server-side execution of a GraphQL operation.\n * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.\n */\n errors?: ReadonlyArray<GraphQLFormattedError>;\n /**\n * The single Error object that is passed to onError and useQuery hooks, and is often thrown during manual `client.query` calls.\n * This will contain both a NetworkError field and any GraphQLErrors.\n * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.\n */\n error?: ApolloError;\n loading: boolean;\n networkStatus: NetworkStatus;\n // If result.data was read from the cache with missing fields,\n // result.partial will be true. Otherwise, result.partial will be falsy\n // (usually because the property is absent from the result object).\n partial?: boolean;\n}\n\n// This is part of the public API, people write these functions in `updateQueries`.\nexport type MutationQueryReducer<T> = (\n previousResult: Record<string, any>,\n options: {\n mutationResult: FetchResult<Unmasked<T>>;\n queryName: string | undefined;\n queryVariables: Record<string, any>;\n }\n) => Record<string, any>;\n\nexport type MutationQueryReducersMap<T = { [key: string]: any }> = {\n [queryName: string]: MutationQueryReducer<T>;\n};\n\n/**\n * @deprecated Use `MutationUpdaterFunction` instead.\n */\nexport type MutationUpdaterFn<T = { [key: string]: any }> = (\n // The MutationUpdaterFn type is broken because it mistakenly uses the same\n // type parameter T for both the cache and the mutationResult. Do not use this\n // type unless you absolutely need it for backwards compatibility.\n cache: ApolloCache<T>,\n mutationResult: FetchResult<T>\n) => void;\n\nexport type MutationUpdaterFunction<\n TData,\n TVariables,\n TContext,\n TCache extends ApolloCache<any>,\n> = (\n cache: TCache,\n result: Omit<FetchResult<Unmasked<TData>>, \"context\">,\n options: {\n context?: TContext;\n variables?: TVariables;\n }\n) => void;\nexport interface Resolvers {\n [key: string]: {\n [field: string]: Resolver;\n };\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, GraphQLFormattedError } from \"graphql\";\n\nimport type { ApolloCache } from \"../cache/index.js\";\nimport type { FetchResult } from \"../link/core/index.js\";\nimport type { ApolloError } from \"../errors/index.js\";\nimport type { NetworkStatus } from \"./networkStatus.js\";\nimport type { Resolver } from \"./LocalState.js\";\nimport type { ObservableQuery } from \"./ObservableQuery.js\";\nimport type { QueryOptions } from \"./watchQueryOptions.js\";\nimport type { Cache } from \"../cache/index.js\";\nimport type { IsStrictlyAny } from \"../utilities/index.js\";\nimport type { Unmasked } from \"../masking/index.js\";\n\nexport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\n\nexport type MethodKeys<T> = {\n [P in keyof T]: T[P] extends Function ? P : never;\n}[keyof T];\n\nexport interface DefaultContext extends Record<string, any> {}\n\nexport type OnQueryUpdated<TResult> = (\n observableQuery: ObservableQuery<any>,\n diff: Cache.DiffResult<any>,\n lastDiff: Cache.DiffResult<any> | undefined\n) => boolean | TResult;\n\nexport type RefetchQueryDescriptor = string | DocumentNode;\nexport type InternalRefetchQueryDescriptor =\n | RefetchQueryDescriptor\n | QueryOptions;\n\ntype RefetchQueriesIncludeShorthand = \"all\" | \"active\";\n\nexport type RefetchQueriesInclude =\n | RefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\nexport type InternalRefetchQueriesInclude =\n | InternalRefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\n// Used by ApolloClient[\"refetchQueries\"]\n// TODO Improve documentation comments for this public type.\nexport interface RefetchQueriesOptions<\n TCache extends ApolloCache<any>,\n TResult,\n> {\n updateCache?: (cache: TCache) => void;\n // The client.refetchQueries method discourages passing QueryOptions, by\n // restricting the public type of options.include to exclude QueryOptions as\n // an available array element type (see InternalRefetchQueriesInclude for a\n // version of RefetchQueriesInclude that allows legacy QueryOptions objects).\n include?: RefetchQueriesInclude;\n optimistic?: boolean;\n // If no onQueryUpdated function is provided, any queries affected by the\n // updateCache function or included in the options.include array will be\n // refetched by default. Passing null instead of undefined disables this\n // default refetching behavior for affected queries, though included queries\n // will still be refetched.\n onQueryUpdated?: OnQueryUpdated<TResult> | null;\n}\n\n// The client.refetchQueries method returns a thenable (PromiseLike) object\n// whose result is an array of Promise.resolve'd TResult values, where TResult\n// is whatever type the (optional) onQueryUpdated function returns. When no\n// onQueryUpdated function is given, TResult defaults to ApolloQueryResult<any>\n// (thanks to default type parameters for client.refetchQueries).\nexport type RefetchQueriesPromiseResults<TResult> =\n // If onQueryUpdated returns any, all bets are off, so the results array must\n // be a generic any[] array, which is much less confusing than the union type\n // we get if we don't check for any. I hoped `any extends TResult` would do\n // the trick here, instead of IsStrictlyAny, but you can see for yourself what\n // fails in the refetchQueries tests if you try making that simplification.\n IsStrictlyAny<TResult> extends true ? any[]\n : // If the onQueryUpdated function passed to client.refetchQueries returns true\n // or false, that means either to refetch the query (true) or to skip the\n // query (false). Since refetching produces an ApolloQueryResult<any>, and\n // skipping produces nothing, the fully-resolved array of all results produced\n // will be an ApolloQueryResult<any>[], when TResult extends boolean.\n TResult extends boolean ? ApolloQueryResult<any>[]\n : // If onQueryUpdated returns a PromiseLike<U>, that thenable will be passed as\n // an array element to Promise.all, so we infer/unwrap the array type U here.\n TResult extends PromiseLike<infer U> ? U[]\n : // All other onQueryUpdated results end up in the final Promise.all array as\n // themselves, with their original TResult type. Note that TResult will\n // default to ApolloQueryResult<any> if no onQueryUpdated function is passed\n // to client.refetchQueries.\n TResult[];\n\n// The result of client.refetchQueries is thenable/awaitable, if you just want\n// an array of fully resolved results, but you can also access the raw results\n// immediately by examining the additional { queries, results } properties of\n// the RefetchQueriesResult<TResult> object.\nexport interface RefetchQueriesResult<TResult>\n extends Promise<RefetchQueriesPromiseResults<TResult>> {\n // An array of ObservableQuery objects corresponding 1:1 to TResult values\n // in the results arrays (both the TResult[] array below, and the results\n // array resolved by the Promise above).\n queries: ObservableQuery<any>[];\n // These are the raw TResult values returned by any onQueryUpdated functions\n // that were invoked by client.refetchQueries.\n results: InternalRefetchQueriesResult<TResult>[];\n}\n\n// Used by QueryManager[\"refetchQueries\"]\nexport interface InternalRefetchQueriesOptions<\n TCache extends ApolloCache<any>,\n TResult,\n> extends Omit<RefetchQueriesOptions<TCache, TResult>, \"include\"> {\n // Just like the refetchQueries option for a mutation, an array of strings,\n // DocumentNode objects, and/or QueryOptions objects, or one of the shorthand\n // strings \"all\" or \"active\", to select every (active) query.\n include?: InternalRefetchQueriesInclude;\n // This part of the API is a (useful) implementation detail, but need not be\n // exposed in the public client.refetchQueries API (above).\n removeOptimistic?: string;\n}\n\nexport type InternalRefetchQueriesResult<TResult> =\n // If onQueryUpdated returns a boolean, that's equivalent to refetching the\n // query when the boolean is true and skipping the query when false, so the\n // internal type of refetched results is Promise<ApolloQueryResult<any>>.\n TResult extends boolean ? Promise<ApolloQueryResult<any>>\n : // Otherwise, onQueryUpdated returns whatever it returns. If onQueryUpdated is\n // not provided, TResult defaults to Promise<ApolloQueryResult<any>> (see the\n // generic type parameters of client.refetchQueries).\n TResult;\n\nexport type InternalRefetchQueriesMap<TResult> = Map<\n ObservableQuery<any>,\n InternalRefetchQueriesResult<TResult>\n>;\n\n// TODO Remove this unnecessary type in Apollo Client 4.\nexport type { QueryOptions as PureQueryOptions };\n\nexport type OperationVariables = Record<string, any>;\n\nexport interface ApolloQueryResult<T> {\n data: T;\n /**\n * A list of any errors that occurred during server-side execution of a GraphQL operation.\n * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.\n */\n errors?: ReadonlyArray<GraphQLFormattedError>;\n /**\n * The single Error object that is passed to onError and useQuery hooks, and is often thrown during manual `client.query` calls.\n * This will contain both a NetworkError field and any GraphQLErrors.\n * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.\n */\n error?: ApolloError;\n loading: boolean;\n networkStatus: NetworkStatus;\n // If result.data was read from the cache with missing fields,\n // result.partial will be true. Otherwise, result.partial will be falsy\n // (usually because the property is absent from the result object).\n partial?: boolean;\n}\n\n// This is part of the public API, people write these functions in `updateQueries`.\nexport type MutationQueryReducer<T> = (\n previousResult: Record<string, any>,\n options: {\n mutationResult: FetchResult<Unmasked<T>>;\n queryName: string | undefined;\n queryVariables: Record<string, any>;\n }\n) => Record<string, any>;\n\nexport type MutationQueryReducersMap<T = { [key: string]: any }> = {\n [queryName: string]: MutationQueryReducer<T>;\n};\n\n/**\n * @deprecated Use `MutationUpdaterFunction` instead.\n */\nexport type MutationUpdaterFn<T = { [key: string]: any }> = (\n // The MutationUpdaterFn type is broken because it mistakenly uses the same\n // type parameter T for both the cache and the mutationResult. Do not use this\n // type unless you absolutely need it for backwards compatibility.\n cache: ApolloCache<T>,\n mutationResult: FetchResult<T>\n) => void;\n\nexport type MutationUpdaterFunction<\n TData,\n TVariables,\n TContext,\n TCache extends ApolloCache<any>,\n> = (\n cache: TCache,\n result: Omit<FetchResult<Unmasked<TData>>, \"context\">,\n options: {\n context?: TContext;\n variables?: TVariables;\n }\n) => void;\nexport interface Resolvers {\n [key: string]: {\n [field: string]: Resolver;\n };\n}\n"]}
package/dev/dev.cjs CHANGED
@@ -492,7 +492,7 @@ const devError = {
492
492
  }
493
493
  };
494
494
 
495
- var version = "3.13.5";
495
+ var version = "3.13.7";
496
496
 
497
497
  function maybe(thunk) {
498
498
  try {