@apollo/client 3.6.2 → 3.6.3

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
@@ -1090,7 +1090,7 @@ function stringifyForDisplay(value) {
1090
1090
 
1091
1091
  function mergeOptions(defaults, options) {
1092
1092
  return compact(defaults, options, options.variables && {
1093
- variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
1093
+ variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
1094
1094
  });
1095
1095
  }
1096
1096
 
@@ -1298,7 +1298,7 @@ var concat = ApolloLink.concat;
1298
1298
 
1299
1299
  var execute = ApolloLink.execute;
1300
1300
 
1301
- var version = '3.6.2';
1301
+ var version = '3.6.3';
1302
1302
 
1303
1303
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1304
1304
  function parseAndCheckHttpResponse(operations) {
@@ -3948,7 +3948,9 @@ var ObservableQuery = (function (_super) {
3948
3948
  _this.queryInfo = queryInfo;
3949
3949
  _this.queryManager = queryManager;
3950
3950
  _this.isTornDown = false;
3951
- _this.options = tslib.__assign({ initialFetchPolicy: options.fetchPolicy || "cache-first" }, options);
3951
+ var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
3952
+ var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
3953
+ _this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
3952
3954
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3953
3955
  var opDef = getOperationDefinition(_this.query);
3954
3956
  _this.queryName = opDef && opDef.name && opDef.name.value;
@@ -6150,6 +6152,8 @@ var InternalState = (function () {
6150
6152
  function InternalState(client, query) {
6151
6153
  this.client = client;
6152
6154
  this.query = query;
6155
+ this.asyncResolveFns = new Set();
6156
+ this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
6153
6157
  this.ssrDisabledResult = maybeDeepFreeze({
6154
6158
  loading: true,
6155
6159
  data: void 0,
@@ -6166,6 +6170,15 @@ var InternalState = (function () {
6166
6170
  verifyDocumentType(query, exports.DocumentType.Query);
6167
6171
  }
6168
6172
  InternalState.prototype.forceUpdate = function () {
6173
+ __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
6174
+ };
6175
+ InternalState.prototype.asyncUpdate = function () {
6176
+ var _this = this;
6177
+ return new Promise(function (resolve) {
6178
+ _this.asyncResolveFns.add(resolve);
6179
+ _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
6180
+ _this.forceUpdate();
6181
+ });
6169
6182
  };
6170
6183
  InternalState.prototype.useQuery = function (options) {
6171
6184
  var _this = this;
@@ -6220,15 +6233,22 @@ var InternalState = (function () {
6220
6233
  this.client.disableNetworkFetches,
6221
6234
  ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
6222
6235
  this.unsafeHandlePartialRefetch(result);
6223
- return this.toQueryResult(result);
6236
+ var queryResult = this.toQueryResult(result);
6237
+ if (!queryResult.loading && this.asyncResolveFns.size) {
6238
+ this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
6239
+ this.asyncResolveFns.clear();
6240
+ }
6241
+ return queryResult;
6224
6242
  };
6225
6243
  InternalState.prototype.useOptions = function (options) {
6226
6244
  var _a;
6227
6245
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6228
6246
  var currentWatchQueryOptions = this.watchQueryOptions;
6229
- if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
6247
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
6248
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
6230
6249
  this.watchQueryOptions = watchQueryOptions;
6231
6250
  if (currentWatchQueryOptions && this.observable) {
6251
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
6232
6252
  this.observable.reobserve(watchQueryOptions);
6233
6253
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6234
6254
  this.result = void 0;
@@ -6237,7 +6257,8 @@ var InternalState = (function () {
6237
6257
  this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
6238
6258
  this.onError = options.onError || InternalState.prototype.onError;
6239
6259
  if ((this.renderPromises || this.client.disableNetworkFetches) &&
6240
- this.queryHookOptions.ssr === false) {
6260
+ this.queryHookOptions.ssr === false &&
6261
+ !this.queryHookOptions.skip) {
6241
6262
  this.result = this.ssrDisabledResult;
6242
6263
  }
6243
6264
  else if (this.queryHookOptions.skip ||
@@ -6250,51 +6271,38 @@ var InternalState = (function () {
6250
6271
  }
6251
6272
  };
6252
6273
  InternalState.prototype.createWatchQueryOptions = function (_a) {
6274
+ var _b;
6253
6275
  if (_a === void 0) { _a = {}; }
6254
- var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var defaultOptions = _a.defaultOptions, otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
6255
- var toMerge = [];
6256
- var globalDefaults = this.client.defaultOptions.watchQuery;
6257
- if (globalDefaults)
6258
- toMerge.push(globalDefaults);
6259
- if (defaultOptions)
6260
- toMerge.push(defaultOptions);
6261
- var latestOptions = this.observable && this.observable.options;
6262
- if (latestOptions && toMerge.length) {
6263
- var defaults_1 = toMerge.reduce(mergeOptions, Object.create(null));
6264
- toMerge.length = 1;
6265
- toMerge[0] = defaults_1;
6266
- Object.keys(defaults_1).forEach(function (defaultOptionName) {
6267
- var currentOptionValue = latestOptions[defaultOptionName];
6268
- if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
6269
- !equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
6270
- defaults_1[defaultOptionName] = defaultOptionName === "variables"
6271
- ? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
6272
- }
6273
- });
6274
- }
6275
- toMerge.push(otherOptions);
6276
- var merged = toMerge.reduce(mergeOptions, Object.create(null));
6277
- var watchQueryOptions = Object.assign(merged, { query: this.query });
6276
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; _a.defaultOptions; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
6277
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6278
6278
  if (this.renderPromises &&
6279
6279
  (watchQueryOptions.fetchPolicy === 'network-only' ||
6280
6280
  watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6281
6281
  watchQueryOptions.fetchPolicy = 'cache-first';
6282
6282
  }
6283
- else if (!watchQueryOptions.fetchPolicy) {
6284
- watchQueryOptions.fetchPolicy = 'cache-first';
6283
+ if (!watchQueryOptions.variables) {
6284
+ watchQueryOptions.variables = {};
6285
6285
  }
6286
6286
  if (skip) {
6287
- var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
6287
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
6288
6288
  Object.assign(watchQueryOptions, {
6289
6289
  initialFetchPolicy: initialFetchPolicy,
6290
6290
  fetchPolicy: 'standby',
6291
6291
  });
6292
6292
  }
6293
- if (!watchQueryOptions.variables) {
6294
- watchQueryOptions.variables = {};
6293
+ else if (!watchQueryOptions.fetchPolicy) {
6294
+ watchQueryOptions.fetchPolicy =
6295
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
6296
+ this.getDefaultFetchPolicy();
6295
6297
  }
6296
6298
  return watchQueryOptions;
6297
6299
  };
6300
+ InternalState.prototype.getDefaultFetchPolicy = function () {
6301
+ var _a, _b;
6302
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
6303
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6304
+ "cache-first");
6305
+ };
6298
6306
  InternalState.prototype.onCompleted = function (data) { };
6299
6307
  InternalState.prototype.onError = function (error) { };
6300
6308
  InternalState.prototype.useObservableQuery = function () {
@@ -6302,7 +6310,7 @@ var InternalState = (function () {
6302
6310
  this.renderPromises
6303
6311
  && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6304
6312
  || this.observable
6305
- || this.client.watchQuery(tslib.__assign({}, this.watchQueryOptions));
6313
+ || this.client.watchQuery(mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
6306
6314
  this.obsQueryFields = React.useMemo(function () { return ({
6307
6315
  refetch: obsQuery.refetch.bind(obsQuery),
6308
6316
  reobserve: obsQuery.reobserve.bind(obsQuery),
@@ -6312,11 +6320,11 @@ var InternalState = (function () {
6312
6320
  stopPolling: obsQuery.stopPolling.bind(obsQuery),
6313
6321
  subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6314
6322
  }); }, [obsQuery]);
6315
- if (this.renderPromises) {
6323
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
6324
+ this.queryHookOptions.skip);
6325
+ if (this.renderPromises && ssrAllowed) {
6316
6326
  this.renderPromises.registerSSRObservable(obsQuery);
6317
- var ssrAllowed = !(this.queryHookOptions.ssr === false ||
6318
- this.queryHookOptions.skip);
6319
- if (ssrAllowed && obsQuery.getCurrentResult().loading) {
6327
+ if (obsQuery.getCurrentResult().loading) {
6320
6328
  this.renderPromises.addObservableQueryPromise(obsQuery);
6321
6329
  }
6322
6330
  }
@@ -6385,12 +6393,9 @@ var EAGER_METHODS = [
6385
6393
  function useLazyQuery(query, options) {
6386
6394
  var internalState = useInternalState(useApolloClient(options && options.client), query);
6387
6395
  var execOptionsRef = React.useRef();
6388
- var defaultOptions = internalState.client.defaultOptions.watchQuery;
6389
- var initialFetchPolicy = (options && options.fetchPolicy) ||
6390
- (execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
6391
- (defaultOptions && defaultOptions.fetchPolicy) ||
6392
- "cache-first";
6393
6396
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
6397
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
6398
+ internalState.getDefaultFetchPolicy();
6394
6399
  var result = Object.assign(useQueryResult, {
6395
6400
  called: !!execOptionsRef.current,
6396
6401
  });
@@ -6414,22 +6419,12 @@ function useLazyQuery(query, options) {
6414
6419
  }, []);
6415
6420
  Object.assign(result, eagerMethods);
6416
6421
  var execute = React.useCallback(function (executeOptions) {
6417
- var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6422
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6418
6423
  fetchPolicy: initialFetchPolicy,
6419
- }).then(function (apolloQueryResult) {
6420
- apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
6421
- if (apolloQueryResult.error ||
6422
- isNonEmptyArray(apolloQueryResult.errors)) {
6423
- var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
6424
- if (errorPolicy === "none") {
6425
- throw apolloQueryResult.error || new ApolloError({
6426
- graphQLErrors: apolloQueryResult.errors,
6427
- });
6428
- }
6429
- }
6430
- return internalState.toQueryResult(apolloQueryResult);
6431
- }).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6432
- internalState.forceUpdate();
6424
+ };
6425
+ var promise = internalState
6426
+ .asyncUpdate()
6427
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6433
6428
  promise.catch(function () { });
6434
6429
  return promise;
6435
6430
  }, []);