@apollo/client 3.8.0-alpha.4 → 3.8.0-alpha.5

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/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  [![npm version](https://badge.fury.io/js/%40apollo%2Fclient.svg)](https://badge.fury.io/js/%40apollo%2Fclient)
6
6
  [![Build Status](https://circleci.com/gh/apollographql/apollo-client.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-client)
7
7
  [![Join the community](https://img.shields.io/discourse/status?label=Join%20the%20community&server=https%3A%2F%2Fcommunity.apollographql.com)](https://community.apollographql.com)
8
+ [![Join our Discord server](https://img.shields.io/discord/1022972389463687228.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square)](https://discord.gg/graphos)
8
9
 
9
10
  Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components that fetch data via GraphQL.
10
11
 
package/apollo-client.cjs CHANGED
@@ -1345,7 +1345,7 @@ var concat = ApolloLink.concat;
1345
1345
 
1346
1346
  var execute = ApolloLink.execute;
1347
1347
 
1348
- var version = '3.8.0-alpha.4';
1348
+ var version = '3.8.0-alpha.5';
1349
1349
 
1350
1350
  function isNodeResponse(value) {
1351
1351
  return !!value.body;
@@ -6652,11 +6652,19 @@ var InternalState = (function () {
6652
6652
  InternalState.prototype.forceUpdate = function () {
6653
6653
  __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
6654
6654
  };
6655
- InternalState.prototype.asyncUpdate = function () {
6655
+ InternalState.prototype.asyncUpdate = function (signal) {
6656
6656
  var _this = this;
6657
- return new Promise(function (resolve) {
6657
+ return new Promise(function (resolve, reject) {
6658
+ var watchQueryOptions = _this.watchQueryOptions;
6659
+ var handleAborted = function () {
6660
+ _this.asyncResolveFns.delete(resolve);
6661
+ _this.optionsToIgnoreOnce.delete(watchQueryOptions);
6662
+ signal.removeEventListener('abort', handleAborted);
6663
+ reject(signal.reason);
6664
+ };
6658
6665
  _this.asyncResolveFns.add(resolve);
6659
- _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
6666
+ _this.optionsToIgnoreOnce.add(watchQueryOptions);
6667
+ signal.addEventListener('abort', handleAborted);
6660
6668
  _this.forceUpdate();
6661
6669
  });
6662
6670
  };
@@ -6895,6 +6903,7 @@ var EAGER_METHODS = [
6895
6903
  'subscribeToMore',
6896
6904
  ];
6897
6905
  function useLazyQuery(query, options) {
6906
+ var abortControllersRef = React.useRef(new Set());
6898
6907
  var internalState = useInternalState(useApolloClient(options && options.client), query);
6899
6908
  var execOptionsRef = React.useRef();
6900
6909
  var merged = execOptionsRef.current
@@ -6925,14 +6934,28 @@ function useLazyQuery(query, options) {
6925
6934
  return eagerMethods;
6926
6935
  }, []);
6927
6936
  Object.assign(result, eagerMethods);
6937
+ React.useEffect(function () {
6938
+ return function () {
6939
+ abortControllersRef.current.forEach(function (controller) {
6940
+ controller.abort();
6941
+ });
6942
+ };
6943
+ }, []);
6928
6944
  var execute = React.useCallback(function (executeOptions) {
6945
+ var controller = new AbortController();
6946
+ abortControllersRef.current.add(controller);
6929
6947
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6930
6948
  fetchPolicy: initialFetchPolicy,
6931
6949
  };
6932
6950
  var promise = internalState
6933
- .asyncUpdate()
6934
- .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6935
- promise.catch(function () { });
6951
+ .asyncUpdate(controller.signal)
6952
+ .then(function (queryResult) {
6953
+ abortControllersRef.current.delete(controller);
6954
+ return Object.assign(queryResult, eagerMethods);
6955
+ });
6956
+ promise.catch(function () {
6957
+ abortControllersRef.current.delete(controller);
6958
+ });
6936
6959
  return promise;
6937
6960
  }, []);
6938
6961
  return [execute, result];
@@ -6973,7 +6996,7 @@ function useMutation(mutation, options) {
6973
6996
  var mutationId = ++ref.current.mutationId;
6974
6997
  var clientOptions = mergeOptions(baseOptions, executeOptions);
6975
6998
  return client.mutate(clientOptions).then(function (response) {
6976
- var _a, _b, _c;
6999
+ var _a;
6977
7000
  var data = response.data, errors = response.errors;
6978
7001
  var error = errors && errors.length > 0
6979
7002
  ? new ApolloError({ graphQLErrors: errors })
@@ -6991,11 +7014,11 @@ function useMutation(mutation, options) {
6991
7014
  setResult(ref.current.result = result_1);
6992
7015
  }
6993
7016
  }
6994
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data, clientOptions);
6995
- (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data, clientOptions);
7017
+ var onCompleted = executeOptions.onCompleted || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted);
7018
+ onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
6996
7019
  return response;
6997
7020
  }).catch(function (error) {
6998
- var _a, _b, _c, _d;
7021
+ var _a;
6999
7022
  if (mutationId === ref.current.mutationId &&
7000
7023
  ref.current.isMounted) {
7001
7024
  var result_2 = {
@@ -7009,9 +7032,9 @@ function useMutation(mutation, options) {
7009
7032
  setResult(ref.current.result = result_2);
7010
7033
  }
7011
7034
  }
7012
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
7013
- (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error, clientOptions);
7014
- (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error, clientOptions);
7035
+ var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
7036
+ if (onError) {
7037
+ onError(error, clientOptions);
7015
7038
  return { data: void 0, errors: error };
7016
7039
  }
7017
7040
  throw error;
@@ -7295,6 +7318,7 @@ function useSuspenseQuery_experimental(query, options) {
7295
7318
  }, []);
7296
7319
  return React.useMemo(function () {
7297
7320
  return {
7321
+ client: client,
7298
7322
  data: result.data,
7299
7323
  error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
7300
7324
  fetchMore: function (options) {
@@ -7313,8 +7337,9 @@ function useSuspenseQuery_experimental(query, options) {
7313
7337
  });
7314
7338
  return promise;
7315
7339
  },
7340
+ subscribeToMore: function (options) { return observable.subscribeToMore(options); },
7316
7341
  };
7317
- }, [result, observable, errorPolicy]);
7342
+ }, [client, result, observable, errorPolicy]);
7318
7343
  }
7319
7344
  function validateOptions(options) {
7320
7345
  var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;