@apollo/client 3.8.0-alpha.3 → 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.
Files changed (38) hide show
  1. package/README.md +1 -0
  2. package/apollo-client.cjs +50 -19
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/core/core.cjs +1 -1
  6. package/core/core.cjs.map +1 -1
  7. package/core/core.cjs.native.js +1 -1
  8. package/invariantErrorCodes.js +1 -1
  9. package/package.json +12 -9
  10. package/react/hooks/hooks.cjs +49 -18
  11. package/react/hooks/hooks.cjs.map +1 -1
  12. package/react/hooks/hooks.cjs.native.js +49 -18
  13. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  14. package/react/hooks/useLazyQuery.js +19 -4
  15. package/react/hooks/useLazyQuery.js.map +1 -1
  16. package/react/hooks/useMutation.d.ts.map +1 -1
  17. package/react/hooks/useMutation.js +7 -7
  18. package/react/hooks/useMutation.js.map +1 -1
  19. package/react/hooks/useQuery.d.ts +2 -1
  20. package/react/hooks/useQuery.d.ts.map +1 -1
  21. package/react/hooks/useQuery.js +19 -5
  22. package/react/hooks/useQuery.js.map +1 -1
  23. package/react/hooks/useSuspenseQuery.d.ts +3 -1
  24. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  25. package/react/hooks/useSuspenseQuery.js +6 -4
  26. package/react/hooks/useSuspenseQuery.js.map +1 -1
  27. package/testing/core/core.cjs +17 -0
  28. package/testing/core/core.cjs.map +1 -1
  29. package/testing/core/core.cjs.native.js +17 -0
  30. package/testing/core/index.d.ts +1 -0
  31. package/testing/core/index.d.ts.map +1 -1
  32. package/testing/core/index.js +1 -0
  33. package/testing/core/index.js.map +1 -1
  34. package/testing/core/wait.d.ts +3 -0
  35. package/testing/core/wait.d.ts.map +1 -0
  36. package/testing/core/wait.js +16 -0
  37. package/testing/core/wait.js.map +1 -0
  38. package/version.js +1 -1
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.3';
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
  };
@@ -6833,9 +6841,10 @@ var InternalState = (function () {
6833
6841
  InternalState.prototype.handleErrorOrCompleted = function (result, previousResult) {
6834
6842
  var _this = this;
6835
6843
  if (!result.loading) {
6844
+ var error_1 = this.toApolloError(result);
6836
6845
  Promise.resolve().then(function () {
6837
- if (result.error) {
6838
- _this.onError(result.error);
6846
+ if (error_1) {
6847
+ _this.onError(error_1);
6839
6848
  }
6840
6849
  else if (result.data &&
6841
6850
  (previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus) !== result.networkStatus &&
@@ -6847,6 +6856,11 @@ var InternalState = (function () {
6847
6856
  });
6848
6857
  }
6849
6858
  };
6859
+ InternalState.prototype.toApolloError = function (result) {
6860
+ return isNonEmptyArray(result.errors)
6861
+ ? new ApolloError({ graphQLErrors: result.errors })
6862
+ : result.error;
6863
+ };
6850
6864
  InternalState.prototype.getCurrentResult = function () {
6851
6865
  if (!this.result) {
6852
6866
  this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
@@ -6889,6 +6903,7 @@ var EAGER_METHODS = [
6889
6903
  'subscribeToMore',
6890
6904
  ];
6891
6905
  function useLazyQuery(query, options) {
6906
+ var abortControllersRef = React.useRef(new Set());
6892
6907
  var internalState = useInternalState(useApolloClient(options && options.client), query);
6893
6908
  var execOptionsRef = React.useRef();
6894
6909
  var merged = execOptionsRef.current
@@ -6919,14 +6934,28 @@ function useLazyQuery(query, options) {
6919
6934
  return eagerMethods;
6920
6935
  }, []);
6921
6936
  Object.assign(result, eagerMethods);
6937
+ React.useEffect(function () {
6938
+ return function () {
6939
+ abortControllersRef.current.forEach(function (controller) {
6940
+ controller.abort();
6941
+ });
6942
+ };
6943
+ }, []);
6922
6944
  var execute = React.useCallback(function (executeOptions) {
6945
+ var controller = new AbortController();
6946
+ abortControllersRef.current.add(controller);
6923
6947
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6924
6948
  fetchPolicy: initialFetchPolicy,
6925
6949
  };
6926
6950
  var promise = internalState
6927
- .asyncUpdate()
6928
- .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6929
- 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
+ });
6930
6959
  return promise;
6931
6960
  }, []);
6932
6961
  return [execute, result];
@@ -6967,7 +6996,7 @@ function useMutation(mutation, options) {
6967
6996
  var mutationId = ++ref.current.mutationId;
6968
6997
  var clientOptions = mergeOptions(baseOptions, executeOptions);
6969
6998
  return client.mutate(clientOptions).then(function (response) {
6970
- var _a, _b, _c;
6999
+ var _a;
6971
7000
  var data = response.data, errors = response.errors;
6972
7001
  var error = errors && errors.length > 0
6973
7002
  ? new ApolloError({ graphQLErrors: errors })
@@ -6985,11 +7014,11 @@ function useMutation(mutation, options) {
6985
7014
  setResult(ref.current.result = result_1);
6986
7015
  }
6987
7016
  }
6988
- (_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);
6989
- (_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);
6990
7019
  return response;
6991
7020
  }).catch(function (error) {
6992
- var _a, _b, _c, _d;
7021
+ var _a;
6993
7022
  if (mutationId === ref.current.mutationId &&
6994
7023
  ref.current.isMounted) {
6995
7024
  var result_2 = {
@@ -7003,9 +7032,9 @@ function useMutation(mutation, options) {
7003
7032
  setResult(ref.current.result = result_2);
7004
7033
  }
7005
7034
  }
7006
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
7007
- (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error, clientOptions);
7008
- (_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);
7009
7038
  return { data: void 0, errors: error };
7010
7039
  }
7011
7040
  throw error;
@@ -7252,9 +7281,9 @@ function useSuspenseQuery_experimental(query, options) {
7252
7281
  var hasFullResult = result.data && !result.partial;
7253
7282
  var hasPartialResult = result.data && result.partial;
7254
7283
  var usePartialResult = returnPartialData && hasPartialResult;
7284
+ var allowsThrownErrors = errorPolicy === 'none' && (!deferred || !hasPartialResult);
7255
7285
  if (result.error &&
7256
- errorPolicy === 'none' &&
7257
- (!deferred || !hasPartialResult)) {
7286
+ (result.error.networkError || allowsThrownErrors)) {
7258
7287
  throw result.error;
7259
7288
  }
7260
7289
  if (result.loading) {
@@ -7289,6 +7318,7 @@ function useSuspenseQuery_experimental(query, options) {
7289
7318
  }, []);
7290
7319
  return React.useMemo(function () {
7291
7320
  return {
7321
+ client: client,
7292
7322
  data: result.data,
7293
7323
  error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
7294
7324
  fetchMore: function (options) {
@@ -7307,8 +7337,9 @@ function useSuspenseQuery_experimental(query, options) {
7307
7337
  });
7308
7338
  return promise;
7309
7339
  },
7340
+ subscribeToMore: function (options) { return observable.subscribeToMore(options); },
7310
7341
  };
7311
- }, [result, observable, errorPolicy]);
7342
+ }, [client, result, observable, errorPolicy]);
7312
7343
  }
7313
7344
  function validateOptions(options) {
7314
7345
  var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;