@apollo/client 3.6.0-beta.6 → 3.6.0-beta.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.
package/apollo-client.cjs CHANGED
@@ -703,7 +703,7 @@ function removeClientSetsFromDocument(document) {
703
703
  return modifiedDoc;
704
704
  }
705
705
 
706
- var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
706
+ var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
707
707
  function mergeDeep() {
708
708
  var sources = [];
709
709
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -740,7 +740,7 @@ var DeepMerger = (function () {
740
740
  }
741
741
  if (isNonNullObject(source) && isNonNullObject(target)) {
742
742
  Object.keys(source).forEach(function (sourceKey) {
743
- if (hasOwnProperty$3.call(target, sourceKey)) {
743
+ if (hasOwnProperty$4.call(target, sourceKey)) {
744
744
  var targetValue = target[sourceKey];
745
745
  if (source[sourceKey] !== targetValue) {
746
746
  var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
@@ -1291,9 +1291,9 @@ var concat = ApolloLink.concat;
1291
1291
 
1292
1292
  var execute = ApolloLink.execute;
1293
1293
 
1294
- var version = '3.6.0-beta.6';
1294
+ var version = '3.6.0-beta.7';
1295
1295
 
1296
- var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1296
+ var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1297
1297
  function parseAndCheckHttpResponse(operations) {
1298
1298
  return function (response) { return response
1299
1299
  .text()
@@ -1315,8 +1315,8 @@ function parseAndCheckHttpResponse(operations) {
1315
1315
  throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1316
1316
  }
1317
1317
  if (!Array.isArray(result) &&
1318
- !hasOwnProperty$2.call(result, 'data') &&
1319
- !hasOwnProperty$2.call(result, 'errors')) {
1318
+ !hasOwnProperty$3.call(result, 'data') &&
1319
+ !hasOwnProperty$3.call(result, 'errors')) {
1320
1320
  throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1321
1321
  ? operations.map(function (op) { return op.operationName; })
1322
1322
  : operations.operationName, "'."));
@@ -3905,7 +3905,7 @@ function isNetworkRequestInFlight(networkStatus) {
3905
3905
  return networkStatus ? networkStatus < 7 : false;
3906
3906
  }
3907
3907
 
3908
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3908
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3909
3909
  var warnedAboutUpdateQuery = false;
3910
3910
  var ObservableQuery = (function (_super) {
3911
3911
  tslib.__extends(ObservableQuery, _super);
@@ -4061,7 +4061,7 @@ var ObservableQuery = (function (_super) {
4061
4061
  else {
4062
4062
  reobserveOptions.fetchPolicy = 'network-only';
4063
4063
  }
4064
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4064
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4065
4065
  var queryDef = getQueryDefinition(this.options.query);
4066
4066
  var vars = queryDef.variableDefinitions;
4067
4067
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
@@ -4870,10 +4870,10 @@ function shouldWriteResult(result, errorPolicy) {
4870
4870
  return writeWithErrors;
4871
4871
  }
4872
4872
 
4873
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4873
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4874
4874
  var QueryManager = (function () {
4875
4875
  function QueryManager(_a) {
4876
- var cache = _a.cache, link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
4876
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
4877
4877
  this.clientAwareness = {};
4878
4878
  this.queries = new Map();
4879
4879
  this.fetchCancelFns = new Map();
@@ -4884,6 +4884,7 @@ var QueryManager = (function () {
4884
4884
  this.inFlightLinkObservables = new Map();
4885
4885
  this.cache = cache;
4886
4886
  this.link = link;
4887
+ this.defaultOptions = defaultOptions || Object.create(null);
4887
4888
  this.queryDeduplication = queryDeduplication;
4888
4889
  this.clientAwareness = clientAwareness;
4889
4890
  this.localState = localState || new LocalState({ cache: cache });
@@ -4905,11 +4906,12 @@ var QueryManager = (function () {
4905
4906
  this.fetchCancelFns.clear();
4906
4907
  };
4907
4908
  QueryManager.prototype.mutate = function (_a) {
4908
- var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _b = _a.refetchQueries, refetchQueries = _b === void 0 ? [] : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _d = _a.errorPolicy, errorPolicy = _d === void 0 ? 'none' : _d, _e = _a.fetchPolicy, fetchPolicy = _e === void 0 ? 'network-only' : _e, keepRootFields = _a.keepRootFields, context = _a.context;
4909
+ var _b, _c;
4910
+ 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;
4909
4911
  return tslib.__awaiter(this, void 0, void 0, function () {
4910
4912
  var mutationId, mutationStoreValue, self;
4911
- return tslib.__generator(this, function (_f) {
4912
- switch (_f.label) {
4913
+ return tslib.__generator(this, function (_h) {
4914
+ switch (_h.label) {
4913
4915
  case 0:
4914
4916
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4915
4917
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4921,8 +4923,8 @@ var QueryManager = (function () {
4921
4923
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4922
4924
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4923
4925
  case 1:
4924
- variables = (_f.sent());
4925
- _f.label = 2;
4926
+ variables = (_h.sent());
4927
+ _h.label = 2;
4926
4928
  case 2:
4927
4929
  mutationStoreValue = this.mutationStore &&
4928
4930
  (this.mutationStore[mutationId] = {
@@ -5023,7 +5025,7 @@ var QueryManager = (function () {
5023
5025
  this.queries.forEach(function (_a, queryId) {
5024
5026
  var observableQuery = _a.observableQuery;
5025
5027
  var queryName = observableQuery && observableQuery.queryName;
5026
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5028
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5027
5029
  return;
5028
5030
  }
5029
5031
  var updater = updateQueries_1[queryName];
@@ -5482,7 +5484,8 @@ var QueryManager = (function () {
5482
5484
  var query = this.transform(options.query).document;
5483
5485
  var variables = this.getVariables(query, options.variables);
5484
5486
  var queryInfo = this.getQuery(queryId);
5485
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? "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;
5487
+ var defaults = this.defaultOptions.watchQuery;
5488
+ 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;
5486
5489
  var normalized = Object.assign({}, options, {
5487
5490
  query: query,
5488
5491
  variables: variables,
@@ -5700,7 +5703,6 @@ function mergeOptions(defaults, options) {
5700
5703
  var ApolloClient = (function () {
5701
5704
  function ApolloClient(options) {
5702
5705
  var _this = this;
5703
- this.defaultOptions = {};
5704
5706
  this.resetStoreCallbacks = [];
5705
5707
  this.clearStoreCallbacks = [];
5706
5708
  var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
@@ -5721,7 +5723,7 @@ var ApolloClient = (function () {
5721
5723
  this.cache = cache;
5722
5724
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5723
5725
  this.queryDeduplication = queryDeduplication;
5724
- this.defaultOptions = defaultOptions || {};
5726
+ this.defaultOptions = defaultOptions || Object.create(null);
5725
5727
  this.typeDefs = typeDefs;
5726
5728
  if (ssrForceFetchDelay) {
5727
5729
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5768,6 +5770,7 @@ var ApolloClient = (function () {
5768
5770
  this.queryManager = new QueryManager({
5769
5771
  cache: this.cache,
5770
5772
  link: this.link,
5773
+ defaultOptions: this.defaultOptions,
5771
5774
  queryDeduplication: queryDeduplication,
5772
5775
  ssrMode: ssrMode,
5773
5776
  clientAwareness: {
@@ -6054,227 +6057,256 @@ function verifyDocumentType(document, type) {
6054
6057
  "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6055
6058
  }
6056
6059
 
6060
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6057
6061
  function useQuery(query, options) {
6058
- var _a;
6059
- var context = React.useContext(getApolloContext());
6060
- var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6061
- var defaultWatchQueryOptions = client.defaultOptions.watchQuery;
6062
- verifyDocumentType(query, exports.DocumentType.Query);
6063
- var _b = React.useState(function () {
6064
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6065
- var obsQuery = null;
6066
- if (context.renderPromises) {
6067
- obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
6068
- }
6069
- if (!obsQuery) {
6070
- obsQuery = client.watchQuery(watchQueryOptions);
6071
- if (context.renderPromises) {
6072
- context.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
6073
- }
6074
- }
6075
- if (context.renderPromises &&
6076
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6077
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6078
- obsQuery.getCurrentResult().loading) {
6079
- context.renderPromises.addQueryPromise({
6080
- getOptions: function () { return createWatchQueryOptions(query, options, defaultWatchQueryOptions); },
6081
- fetchData: function () { return new Promise(function (resolve) {
6082
- var sub = obsQuery.subscribe({
6083
- next: function (result) {
6084
- if (!result.loading) {
6062
+ return useInternalState(useApolloClient(options && options.client), query).useQuery(options);
6063
+ }
6064
+ function useInternalState(client, query) {
6065
+ var stateRef = React.useRef();
6066
+ if (!stateRef.current ||
6067
+ client !== stateRef.current.client ||
6068
+ query !== stateRef.current.query) {
6069
+ stateRef.current = new InternalState(client, query);
6070
+ }
6071
+ var state = stateRef.current;
6072
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6073
+ state.forceUpdate = function () {
6074
+ setTick(function (tick) { return tick + 1; });
6075
+ };
6076
+ return state;
6077
+ }
6078
+ var InternalState = (function () {
6079
+ function InternalState(client, query) {
6080
+ this.client = client;
6081
+ this.query = query;
6082
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6083
+ verifyDocumentType(query, exports.DocumentType.Query);
6084
+ }
6085
+ InternalState.prototype.forceUpdate = function () {
6086
+ };
6087
+ InternalState.prototype.useQuery = function (options) {
6088
+ this.useOptions(options);
6089
+ var obsQuery = this.useObservableQuery();
6090
+ this.useSubscriptionEffect(obsQuery);
6091
+ var result = this.getCurrentResult();
6092
+ this.unsafeHandlePartialRefetch(result);
6093
+ return this.toQueryResult(result);
6094
+ };
6095
+ InternalState.prototype.useOptions = function (options) {
6096
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6097
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options || {});
6098
+ if (!equality.equal(watchQueryOptions, this.watchQueryOptions)) {
6099
+ this.watchQueryOptions = watchQueryOptions;
6100
+ }
6101
+ this.ssrDisabled = !!(options && (options.ssr === false ||
6102
+ options.skip));
6103
+ this.onCompleted = options
6104
+ && options.onCompleted
6105
+ || InternalState.prototype.onCompleted;
6106
+ this.onError = options
6107
+ && options.onError
6108
+ || InternalState.prototype.onError;
6109
+ };
6110
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6111
+ var _b;
6112
+ if (_a === void 0) { _a = {}; }
6113
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6114
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6115
+ if (skip) {
6116
+ watchQueryOptions.fetchPolicy = 'standby';
6117
+ }
6118
+ else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
6119
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6120
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6121
+ watchQueryOptions.fetchPolicy = 'cache-first';
6122
+ }
6123
+ else if (!watchQueryOptions.fetchPolicy) {
6124
+ var defaultOptions = this.client.defaultOptions.watchQuery;
6125
+ watchQueryOptions.fetchPolicy =
6126
+ defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
6127
+ }
6128
+ if (!watchQueryOptions.variables) {
6129
+ watchQueryOptions.variables = {};
6130
+ }
6131
+ return watchQueryOptions;
6132
+ };
6133
+ InternalState.prototype.onCompleted = function (data) { };
6134
+ InternalState.prototype.onError = function (error) { };
6135
+ InternalState.prototype.useObservableQuery = function () {
6136
+ var _this = this;
6137
+ var obsQuery = this.observable =
6138
+ this.renderPromises
6139
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6140
+ || this.observable
6141
+ || this.client.watchQuery(this.watchQueryOptions);
6142
+ this.obsQueryFields = React.useMemo(function () { return ({
6143
+ refetch: obsQuery.refetch.bind(obsQuery),
6144
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6145
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6146
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6147
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6148
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6149
+ }); }, [obsQuery]);
6150
+ if (this.renderPromises) {
6151
+ this.renderPromises.registerSSRObservable(obsQuery);
6152
+ if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
6153
+ this.renderPromises.addQueryPromise({
6154
+ getOptions: function () { return obsQuery.options; },
6155
+ fetchData: function () { return new Promise(function (resolve) {
6156
+ var sub = obsQuery.subscribe({
6157
+ next: function (result) {
6158
+ if (!result.loading) {
6159
+ resolve();
6160
+ sub.unsubscribe();
6161
+ }
6162
+ },
6163
+ error: function () {
6085
6164
  resolve();
6086
6165
  sub.unsubscribe();
6087
- }
6088
- },
6089
- error: function () {
6090
- resolve();
6091
- sub.unsubscribe();
6092
- },
6093
- complete: function () {
6094
- resolve();
6095
- },
6096
- });
6097
- }); },
6098
- }, function () { return null; });
6166
+ },
6167
+ complete: function () {
6168
+ resolve();
6169
+ },
6170
+ });
6171
+ }); },
6172
+ }, function () { return null; });
6173
+ obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
6174
+ }
6099
6175
  }
6176
+ var prevOptionsRef = React.useRef({
6177
+ watchQueryOptions: this.watchQueryOptions,
6178
+ });
6179
+ React.useEffect(function () {
6180
+ if (_this.renderPromises) ;
6181
+ else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
6182
+ obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
6183
+ prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
6184
+ _this.setResult(obsQuery.getCurrentResult());
6185
+ }
6186
+ }, [obsQuery, this.watchQueryOptions]);
6100
6187
  return obsQuery;
6101
- }), obsQuery = _b[0], setObsQuery = _b[1];
6102
- var _c = React.useState(function () {
6103
- var _a, _b;
6104
- var result = obsQuery.getCurrentResult();
6105
- if (!result.loading && options) {
6188
+ };
6189
+ InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
6190
+ var _this = this;
6191
+ React.useEffect(function () {
6192
+ if (_this.renderPromises) {
6193
+ return;
6194
+ }
6195
+ var onNext = function () {
6196
+ var previousResult = _this.result;
6197
+ var result = obsQuery.getCurrentResult();
6198
+ if (previousResult &&
6199
+ previousResult.loading === result.loading &&
6200
+ previousResult.networkStatus === result.networkStatus &&
6201
+ equality.equal(previousResult.data, result.data)) {
6202
+ return;
6203
+ }
6204
+ _this.setResult(result);
6205
+ };
6206
+ var onError = function (error) {
6207
+ var last = obsQuery["last"];
6208
+ subscription.unsubscribe();
6209
+ try {
6210
+ obsQuery.resetLastResults();
6211
+ subscription = obsQuery.subscribe(onNext, onError);
6212
+ }
6213
+ finally {
6214
+ obsQuery["last"] = last;
6215
+ }
6216
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6217
+ throw error;
6218
+ }
6219
+ var previousResult = _this.result;
6220
+ if (!previousResult ||
6221
+ (previousResult && previousResult.loading) ||
6222
+ !equality.equal(error, previousResult.error)) {
6223
+ _this.setResult({
6224
+ data: (previousResult && previousResult.data),
6225
+ error: error,
6226
+ loading: false,
6227
+ networkStatus: exports.NetworkStatus.error,
6228
+ });
6229
+ }
6230
+ };
6231
+ var subscription = obsQuery.subscribe(onNext, onError);
6232
+ return function () { return subscription.unsubscribe(); };
6233
+ }, [
6234
+ obsQuery,
6235
+ this.renderPromises,
6236
+ this.client.disableNetworkFetches,
6237
+ ]);
6238
+ };
6239
+ InternalState.prototype.setResult = function (nextResult) {
6240
+ var previousResult = this.result;
6241
+ if (previousResult && previousResult.data) {
6242
+ this.previousData = previousResult.data;
6243
+ }
6244
+ this.result = nextResult;
6245
+ this.forceUpdate();
6246
+ this.handleErrorOrCompleted(nextResult);
6247
+ };
6248
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6249
+ if (!result.loading) {
6106
6250
  if (result.error) {
6107
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6251
+ this.onError(result.error);
6108
6252
  }
6109
6253
  else if (result.data) {
6110
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6254
+ this.onCompleted(result.data);
6111
6255
  }
6112
6256
  }
6113
- return result;
6114
- }), result = _c[0], setResult = _c[1];
6115
- var ref = React.useRef({
6116
- client: client,
6117
- query: query,
6118
- options: options,
6119
- result: result,
6120
- previousData: void 0,
6121
- watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),
6122
- });
6123
- React.useEffect(function () {
6124
- var _a, _b;
6125
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6126
- var nextResult;
6127
- if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
6128
- var obsQuery_1 = client.watchQuery(watchQueryOptions);
6129
- setObsQuery(obsQuery_1);
6130
- nextResult = obsQuery_1.getCurrentResult();
6131
- }
6132
- else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6133
- obsQuery.setOptions(watchQueryOptions).catch(function () { });
6134
- nextResult = obsQuery.getCurrentResult();
6135
- ref.current.watchQueryOptions = watchQueryOptions;
6136
- }
6137
- if (nextResult) {
6138
- var previousResult = ref.current.result;
6139
- if (previousResult.data) {
6140
- ref.current.previousData = previousResult.data;
6141
- }
6142
- setResult(ref.current.result = nextResult);
6143
- if (!nextResult.loading && options) {
6144
- if (nextResult.error) {
6145
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, nextResult.error);
6146
- }
6147
- else if (nextResult.data) {
6148
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, nextResult.data);
6149
- }
6150
- }
6257
+ };
6258
+ InternalState.prototype.getCurrentResult = function () {
6259
+ var result = this.result;
6260
+ if (!result) {
6261
+ result = this.result = this.observable.getCurrentResult();
6262
+ this.handleErrorOrCompleted(result);
6151
6263
  }
6152
- Object.assign(ref.current, { client: client, query: query });
6153
- }, [obsQuery, client, query, options]);
6154
- React.useEffect(function () {
6155
- if (context.renderPromises) {
6156
- return;
6264
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6265
+ this.queryHookOptions.ssr === false) {
6266
+ result = {
6267
+ loading: true,
6268
+ data: void 0,
6269
+ error: void 0,
6270
+ networkStatus: exports.NetworkStatus.loading,
6271
+ };
6157
6272
  }
6158
- var subscription = obsQuery.subscribe(onNext, onError);
6159
- function onNext() {
6160
- var _a, _b;
6161
- var previousResult = ref.current.result;
6162
- var result = obsQuery.getCurrentResult();
6163
- if (previousResult &&
6164
- previousResult.loading === result.loading &&
6165
- previousResult.networkStatus === result.networkStatus &&
6166
- equality.equal(previousResult.data, result.data)) {
6167
- return;
6168
- }
6169
- if (previousResult.data) {
6170
- ref.current.previousData = previousResult.data;
6171
- }
6172
- setResult(ref.current.result = result);
6173
- if (!result.loading) {
6174
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
6175
- }
6273
+ else if (this.queryHookOptions.skip ||
6274
+ this.queryHookOptions.fetchPolicy === 'standby') {
6275
+ result = {
6276
+ loading: false,
6277
+ data: void 0,
6278
+ error: void 0,
6279
+ networkStatus: exports.NetworkStatus.ready,
6280
+ };
6176
6281
  }
6177
- function onError(error) {
6178
- var _a, _b;
6179
- var last = obsQuery["last"];
6180
- subscription.unsubscribe();
6181
- try {
6182
- obsQuery.resetLastResults();
6183
- subscription = obsQuery.subscribe(onNext, onError);
6184
- }
6185
- finally {
6186
- obsQuery["last"] = last;
6187
- }
6188
- if (!error.hasOwnProperty('graphQLErrors')) {
6189
- throw error;
6190
- }
6191
- var previousResult = ref.current.result;
6192
- if ((previousResult && previousResult.loading) ||
6193
- !equality.equal(error, previousResult.error)) {
6194
- setResult(ref.current.result = {
6195
- data: previousResult.data,
6196
- error: error,
6197
- loading: false,
6198
- networkStatus: exports.NetworkStatus.error,
6199
- });
6200
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
6201
- }
6282
+ return result;
6283
+ };
6284
+ InternalState.prototype.toQueryResult = function (result) {
6285
+ var queryResult = this.toQueryResultCache.get(result);
6286
+ if (queryResult)
6287
+ return queryResult;
6288
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6289
+ this.toQueryResultCache.set(result, queryResult = tslib.__assign(tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: true, previousData: this.previousData }));
6290
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6291
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6202
6292
  }
6203
- return function () { return subscription.unsubscribe(); };
6204
- }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
6205
- var partial;
6206
- (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
6207
- {
6208
- if (partial &&
6209
- (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
6293
+ return queryResult;
6294
+ };
6295
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6296
+ if (result.partial &&
6297
+ this.queryHookOptions.partialRefetch &&
6210
6298
  !result.loading &&
6211
6299
  (!result.data || Object.keys(result.data).length === 0) &&
6212
- obsQuery.options.fetchPolicy !== 'cache-only') {
6213
- result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
6214
- obsQuery.refetch();
6215
- }
6216
- if (context.renderPromises &&
6217
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6218
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6219
- result.loading) {
6220
- obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(function () { });
6300
+ this.observable.options.fetchPolicy !== 'cache-only') {
6301
+ Object.assign(result, {
6302
+ loading: true,
6303
+ networkStatus: exports.NetworkStatus.refetch,
6304
+ });
6305
+ this.observable.refetch();
6221
6306
  }
6222
- Object.assign(ref.current, { options: options });
6223
- }
6224
- if ((context.renderPromises || client.disableNetworkFetches) &&
6225
- (options === null || options === void 0 ? void 0 : options.ssr) === false) {
6226
- result = ref.current.result = {
6227
- loading: true,
6228
- data: void 0,
6229
- error: void 0,
6230
- networkStatus: exports.NetworkStatus.loading,
6231
- };
6232
- }
6233
- else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6234
- result = {
6235
- loading: false,
6236
- data: void 0,
6237
- error: void 0,
6238
- networkStatus: exports.NetworkStatus.ready,
6239
- };
6240
- }
6241
- if (result.errors && result.errors.length) {
6242
- result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6243
- }
6244
- var obsQueryFields = React.useMemo(function () { return ({
6245
- refetch: obsQuery.refetch.bind(obsQuery),
6246
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
6247
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
6248
- startPolling: obsQuery.startPolling.bind(obsQuery),
6249
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
6250
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6251
- }); }, [obsQuery]);
6252
- return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables, client: client, called: true, previousData: ref.current.previousData }), result);
6253
- }
6254
- function createWatchQueryOptions(query, options, defaultOptions) {
6255
- var _a;
6256
- if (options === void 0) { options = {}; }
6257
- var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var otherOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6258
- var watchQueryOptions = tslib.__assign({ query: query }, otherOptions);
6259
- if (defaultOptions) {
6260
- watchQueryOptions = mergeOptions(defaultOptions, watchQueryOptions);
6261
- }
6262
- if (skip) {
6263
- watchQueryOptions.fetchPolicy = 'standby';
6264
- }
6265
- else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
6266
- (watchQueryOptions.fetchPolicy === 'network-only' ||
6267
- watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6268
- watchQueryOptions.fetchPolicy = 'cache-first';
6269
- }
6270
- else if (!watchQueryOptions.fetchPolicy) {
6271
- watchQueryOptions.fetchPolicy = 'cache-first';
6272
- }
6273
- if (!watchQueryOptions.variables) {
6274
- watchQueryOptions.variables = {};
6275
- }
6276
- return watchQueryOptions;
6277
- }
6307
+ };
6308
+ return InternalState;
6309
+ }());
6278
6310
 
6279
6311
  var EAGER_METHODS = [
6280
6312
  'refetch',