@apollo/client 3.7.3 → 3.7.4

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
 
@@ -21,13 +22,13 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
21
22
 
22
23
  ## Maintainers
23
24
 
24
- - [@benjamn](https://github.com/benjamn)
25
- - [@alessbell](https://github.com/alessbell)
26
- - [@bignimbus](https://github.com/bignimbus)
27
- - [@hwillson](https://github.com/hwillson)
28
- - [@jpvajda](https://github.com/jpvajda)
29
- - [@mrdoombringer](https://github.com/mrdoombringer)
30
- - [@jerelmiller](https://github.com/jerelmiller)
25
+ |Name|Username|
26
+ |---|---|
27
+ |Ben Newman|[@benjamn](https://github.com/benjamn)|
28
+ |Alessia Bellisario|[@alessbell](https://github.com/alessbell)|
29
+ |Jeff Auriemma|[@bignimbus](https://github.com/bignimbus)|
30
+ |Hugh Willson|[@hwillson](https://github.com/hwillson)|
31
+ |Jerel Miller|[@jerelmiller](https://github.com/jerelmiller)|
31
32
 
32
33
  ## Who is Apollo?
33
34
 
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.7.3';
1348
+ var version = '3.7.4';
1349
1349
 
1350
1350
  function isNodeResponse(value) {
1351
1351
  return !!value.body;
@@ -6632,11 +6632,19 @@ var InternalState = (function () {
6632
6632
  InternalState.prototype.forceUpdate = function () {
6633
6633
  __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
6634
6634
  };
6635
- InternalState.prototype.asyncUpdate = function () {
6635
+ InternalState.prototype.asyncUpdate = function (signal) {
6636
6636
  var _this = this;
6637
- return new Promise(function (resolve) {
6637
+ return new Promise(function (resolve, reject) {
6638
+ var watchQueryOptions = _this.watchQueryOptions;
6639
+ var handleAborted = function () {
6640
+ _this.asyncResolveFns.delete(resolve);
6641
+ _this.optionsToIgnoreOnce.delete(watchQueryOptions);
6642
+ signal.removeEventListener('abort', handleAborted);
6643
+ reject(signal.reason);
6644
+ };
6638
6645
  _this.asyncResolveFns.add(resolve);
6639
- _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
6646
+ _this.optionsToIgnoreOnce.add(watchQueryOptions);
6647
+ signal.addEventListener('abort', handleAborted);
6640
6648
  _this.forceUpdate();
6641
6649
  });
6642
6650
  };
@@ -6813,9 +6821,10 @@ var InternalState = (function () {
6813
6821
  InternalState.prototype.handleErrorOrCompleted = function (result) {
6814
6822
  var _this = this;
6815
6823
  if (!result.loading) {
6824
+ var error_1 = this.toApolloError(result);
6816
6825
  Promise.resolve().then(function () {
6817
- if (result.error) {
6818
- _this.onError(result.error);
6826
+ if (error_1) {
6827
+ _this.onError(error_1);
6819
6828
  }
6820
6829
  else if (result.data) {
6821
6830
  _this.onCompleted(result.data);
@@ -6825,6 +6834,11 @@ var InternalState = (function () {
6825
6834
  });
6826
6835
  }
6827
6836
  };
6837
+ InternalState.prototype.toApolloError = function (result) {
6838
+ return isNonEmptyArray(result.errors)
6839
+ ? new ApolloError({ graphQLErrors: result.errors })
6840
+ : result.error;
6841
+ };
6828
6842
  InternalState.prototype.getCurrentResult = function () {
6829
6843
  if (!this.result) {
6830
6844
  this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
@@ -6867,6 +6881,7 @@ var EAGER_METHODS = [
6867
6881
  'subscribeToMore',
6868
6882
  ];
6869
6883
  function useLazyQuery(query, options) {
6884
+ var abortControllersRef = React.useRef(new Set());
6870
6885
  var internalState = useInternalState(useApolloClient(options && options.client), query);
6871
6886
  var execOptionsRef = React.useRef();
6872
6887
  var merged = execOptionsRef.current
@@ -6897,14 +6912,28 @@ function useLazyQuery(query, options) {
6897
6912
  return eagerMethods;
6898
6913
  }, []);
6899
6914
  Object.assign(result, eagerMethods);
6915
+ React.useEffect(function () {
6916
+ return function () {
6917
+ abortControllersRef.current.forEach(function (controller) {
6918
+ controller.abort();
6919
+ });
6920
+ };
6921
+ }, []);
6900
6922
  var execute = React.useCallback(function (executeOptions) {
6923
+ var controller = new AbortController();
6924
+ abortControllersRef.current.add(controller);
6901
6925
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6902
6926
  fetchPolicy: initialFetchPolicy,
6903
6927
  };
6904
6928
  var promise = internalState
6905
- .asyncUpdate()
6906
- .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6907
- promise.catch(function () { });
6929
+ .asyncUpdate(controller.signal)
6930
+ .then(function (queryResult) {
6931
+ abortControllersRef.current.delete(controller);
6932
+ return Object.assign(queryResult, eagerMethods);
6933
+ });
6934
+ promise.catch(function () {
6935
+ abortControllersRef.current.delete(controller);
6936
+ });
6908
6937
  return promise;
6909
6938
  }, []);
6910
6939
  return [execute, result];
@@ -6945,7 +6974,7 @@ function useMutation(mutation, options) {
6945
6974
  var mutationId = ++ref.current.mutationId;
6946
6975
  var clientOptions = mergeOptions(baseOptions, executeOptions);
6947
6976
  return client.mutate(clientOptions).then(function (response) {
6948
- var _a, _b, _c;
6977
+ var _a;
6949
6978
  var data = response.data, errors = response.errors;
6950
6979
  var error = errors && errors.length > 0
6951
6980
  ? new ApolloError({ graphQLErrors: errors })
@@ -6963,11 +6992,11 @@ function useMutation(mutation, options) {
6963
6992
  setResult(ref.current.result = result_1);
6964
6993
  }
6965
6994
  }
6966
- (_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);
6967
- (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data, clientOptions);
6995
+ var onCompleted = executeOptions.onCompleted || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted);
6996
+ onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
6968
6997
  return response;
6969
6998
  }).catch(function (error) {
6970
- var _a, _b, _c, _d;
6999
+ var _a;
6971
7000
  if (mutationId === ref.current.mutationId &&
6972
7001
  ref.current.isMounted) {
6973
7002
  var result_2 = {
@@ -6981,9 +7010,9 @@ function useMutation(mutation, options) {
6981
7010
  setResult(ref.current.result = result_2);
6982
7011
  }
6983
7012
  }
6984
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
6985
- (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error, clientOptions);
6986
- (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error, clientOptions);
7013
+ var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
7014
+ if (onError) {
7015
+ onError(error, clientOptions);
6987
7016
  return { data: void 0, errors: error };
6988
7017
  }
6989
7018
  throw error;