@apollo/client 3.3.7 → 3.3.11

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 (60) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -0
  3. package/apollo-client.cjs.js +66 -52
  4. package/apollo-client.cjs.js.map +1 -1
  5. package/apollo-client.cjs.min.js +1 -1
  6. package/cache/cache.cjs.js +27 -24
  7. package/cache/cache.cjs.js.map +1 -1
  8. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  9. package/cache/inmemory/inMemoryCache.js +4 -1
  10. package/cache/inmemory/inMemoryCache.js.map +1 -1
  11. package/cache/inmemory/reactiveVars.d.ts +1 -0
  12. package/cache/inmemory/reactiveVars.d.ts.map +1 -1
  13. package/cache/inmemory/reactiveVars.js +25 -25
  14. package/cache/inmemory/reactiveVars.js.map +1 -1
  15. package/core/ObservableQuery.d.ts.map +1 -1
  16. package/core/ObservableQuery.js +2 -2
  17. package/core/ObservableQuery.js.map +1 -1
  18. package/core/QueryInfo.d.ts +1 -0
  19. package/core/QueryInfo.d.ts.map +1 -1
  20. package/core/QueryInfo.js +8 -3
  21. package/core/QueryInfo.js.map +1 -1
  22. package/core/core.cjs.js +10 -5
  23. package/core/core.cjs.js.map +1 -1
  24. package/core/index.d.ts +1 -1
  25. package/core/index.d.ts.map +1 -1
  26. package/invariantErrorCodes.js +1 -1
  27. package/package.json +9 -10
  28. package/react/data/MutationData.d.ts +1 -1
  29. package/react/data/MutationData.d.ts.map +1 -1
  30. package/react/data/MutationData.js.map +1 -1
  31. package/react/data/QueryData.d.ts +2 -2
  32. package/react/data/QueryData.d.ts.map +1 -1
  33. package/react/data/QueryData.js.map +1 -1
  34. package/react/hooks/hooks.cjs.js +14 -18
  35. package/react/hooks/hooks.cjs.js.map +1 -1
  36. package/react/hooks/useReactiveVar.d.ts.map +1 -1
  37. package/react/hooks/useReactiveVar.js +3 -0
  38. package/react/hooks/useReactiveVar.js.map +1 -1
  39. package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
  40. package/react/hooks/utils/useBaseQuery.js +11 -18
  41. package/react/hooks/utils/useBaseQuery.js.map +1 -1
  42. package/utilities/graphql/transform.js.map +1 -1
  43. package/utilities/index.d.ts +1 -0
  44. package/utilities/index.d.ts.map +1 -1
  45. package/utilities/index.js +1 -0
  46. package/utilities/index.js.map +1 -1
  47. package/utilities/observables/Concast.d.ts +2 -2
  48. package/utilities/observables/Concast.d.ts.map +1 -1
  49. package/utilities/observables/Concast.js +5 -5
  50. package/utilities/observables/Concast.js.map +1 -1
  51. package/utilities/observables/Observable.d.ts +1 -0
  52. package/utilities/observables/Observable.d.ts.map +1 -1
  53. package/utilities/observables/Observable.js.map +1 -1
  54. package/utilities/observables/subclassing.d.ts +4 -0
  55. package/utilities/observables/subclassing.d.ts.map +1 -0
  56. package/utilities/observables/subclassing.js +12 -0
  57. package/utilities/observables/subclassing.js.map +1 -0
  58. package/utilities/utilities.cjs.js +16 -5
  59. package/utilities/utilities.cjs.js.map +1 -1
  60. package/version.js +1 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
3
+ Copyright (c) 2021 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -20,3 +20,4 @@ The Apollo Client API reference can be found at: <br/>
20
20
 
21
21
  - [@benjamn](https://github.com/benjamn) (Apollo)
22
22
  - [@hwillson](https://github.com/hwillson) (Apollo)
23
+ - [@jcreighton](https://github.com/jcreighton) (Apollo)
@@ -851,6 +851,17 @@ function asyncMap(observable, mapFn, catchFn) {
851
851
  });
852
852
  }
853
853
 
854
+ function fixObservableSubclass(subclass) {
855
+ function set(key) {
856
+ Object.defineProperty(subclass, key, { value: Observable });
857
+ }
858
+ if (typeof Symbol === "function" && Symbol.species) {
859
+ set(Symbol.species);
860
+ }
861
+ set("@@species");
862
+ return subclass;
863
+ }
864
+
854
865
  function isPromiseLike(value) {
855
866
  return value && typeof value.then === "function";
856
867
  }
@@ -914,6 +925,9 @@ var Concast = (function (_super) {
914
925
  _this.handlers.complete();
915
926
  };
916
927
  _this.promise.catch(function (_) { });
928
+ if (typeof sources === "function") {
929
+ sources = [new Observable(sources)];
930
+ }
917
931
  if (isPromiseLike(sources)) {
918
932
  sources.then(function (iterable) { return _this.start(iterable); }, _this.handlers.error);
919
933
  }
@@ -977,11 +991,7 @@ var Concast = (function (_super) {
977
991
  };
978
992
  return Concast;
979
993
  }(Observable));
980
- if (typeof Symbol === "function" && Symbol.species) {
981
- Object.defineProperty(Concast, Symbol.species, {
982
- value: Observable,
983
- });
984
- }
994
+ fixObservableSubclass(Concast);
985
995
 
986
996
  function isNonEmptyArray(value) {
987
997
  return Array.isArray(value) && value.length > 0;
@@ -1217,7 +1227,7 @@ var concat = ApolloLink.concat;
1217
1227
 
1218
1228
  var execute = ApolloLink.execute;
1219
1229
 
1220
- var version = '3.3.7';
1230
+ var version = '3.3.11';
1221
1231
 
1222
1232
  var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1223
1233
  function parseAndCheckHttpResponse(operations) {
@@ -1947,7 +1957,6 @@ var ObservableQuery = (function (_super) {
1947
1957
  this.reobserver.stop();
1948
1958
  delete this.reobserver;
1949
1959
  }
1950
- delete this.options.context;
1951
1960
  this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
1952
1961
  this.subscriptions.clear();
1953
1962
  this.queryManager.stopQuery(this.queryId);
@@ -1956,6 +1965,7 @@ var ObservableQuery = (function (_super) {
1956
1965
  };
1957
1966
  return ObservableQuery;
1958
1967
  }(Observable));
1968
+ fixObservableSubclass(ObservableQuery);
1959
1969
  function defaultSubscriptionObserverErrorCallback(error) {
1960
1970
  process.env.NODE_ENV === "production" || tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
1961
1971
  }
@@ -2960,7 +2970,6 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
2960
2970
  : "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
2961
2971
  }
2962
2972
 
2963
- var varDep = optimism.dep();
2964
2973
  var cacheSlot = new context.Slot();
2965
2974
  function consumeAndIterate(set, callback) {
2966
2975
  if (set.size) {
@@ -2970,13 +2979,22 @@ function consumeAndIterate(set, callback) {
2970
2979
  items_1.forEach(callback);
2971
2980
  }
2972
2981
  }
2973
- var varsByCache = new WeakMap();
2974
- function forgetCache(cache) {
2975
- var vars = varsByCache.get(cache);
2976
- if (vars) {
2977
- consumeAndIterate(vars, function (rv) { return rv.forgetCache(cache); });
2978
- varsByCache.delete(cache);
2982
+ var cacheInfoMap = new WeakMap();
2983
+ function getCacheInfo(cache) {
2984
+ var info = cacheInfoMap.get(cache);
2985
+ if (!info) {
2986
+ cacheInfoMap.set(cache, info = {
2987
+ vars: new Set,
2988
+ dep: optimism.dep(),
2989
+ });
2979
2990
  }
2991
+ return info;
2992
+ }
2993
+ function forgetCache(cache) {
2994
+ getCacheInfo(cache).vars.forEach(function (rv) { return rv.forgetCache(cache); });
2995
+ }
2996
+ function recallCache(cache) {
2997
+ getCacheInfo(cache).vars.forEach(function (rv) { return rv.attachCache(cache); });
2980
2998
  }
2981
2999
  function makeVar(value) {
2982
3000
  var caches = new Set();
@@ -2985,16 +3003,19 @@ function makeVar(value) {
2985
3003
  if (arguments.length > 0) {
2986
3004
  if (value !== newValue) {
2987
3005
  value = newValue;
2988
- varDep.dirty(rv);
2989
- caches.forEach(broadcast);
3006
+ caches.forEach(function (cache) {
3007
+ getCacheInfo(cache).dep.dirty(rv);
3008
+ broadcast(cache);
3009
+ });
2990
3010
  consumeAndIterate(listeners, function (listener) { return listener(value); });
2991
3011
  }
2992
3012
  }
2993
3013
  else {
2994
3014
  var cache = cacheSlot.getValue();
2995
- if (cache)
3015
+ if (cache) {
2996
3016
  attach(cache);
2997
- varDep(rv);
3017
+ getCacheInfo(cache).dep(rv);
3018
+ }
2998
3019
  }
2999
3020
  return value;
3000
3021
  };
@@ -3006,21 +3027,10 @@ function makeVar(value) {
3006
3027
  };
3007
3028
  var attach = rv.attachCache = function (cache) {
3008
3029
  caches.add(cache);
3009
- var vars = varsByCache.get(cache);
3010
- if (!vars)
3011
- varsByCache.set(cache, vars = new Set);
3012
- vars.add(rv);
3030
+ getCacheInfo(cache).vars.add(rv);
3013
3031
  return rv;
3014
3032
  };
3015
- rv.forgetCache = function (cache) {
3016
- var deleted = caches.delete(cache);
3017
- if (deleted) {
3018
- var vars = varsByCache.get(cache);
3019
- if (vars)
3020
- vars.delete(rv);
3021
- }
3022
- return deleted;
3023
- };
3033
+ rv.forgetCache = function (cache) { return caches.delete(cache); };
3024
3034
  return rv;
3025
3035
  }
3026
3036
  function broadcast(cache) {
@@ -3609,6 +3619,9 @@ var InMemoryCache = (function (_super) {
3609
3619
  };
3610
3620
  InMemoryCache.prototype.watch = function (watch) {
3611
3621
  var _this = this;
3622
+ if (!this.watches.size) {
3623
+ recallCache(this);
3624
+ }
3612
3625
  this.watches.add(watch);
3613
3626
  if (watch.immediate) {
3614
3627
  this.maybeBroadcastWatch(watch);
@@ -4050,6 +4063,11 @@ var QueryInfo = (function () {
4050
4063
  }
4051
4064
  return this;
4052
4065
  };
4066
+ QueryInfo.prototype.reset = function () {
4067
+ cancelNotifyTimeout(this);
4068
+ this.diff = null;
4069
+ this.dirty = false;
4070
+ };
4053
4071
  QueryInfo.prototype.getDiff = function (variables) {
4054
4072
  if (variables === void 0) { variables = this.variables; }
4055
4073
  if (this.diff && equality.equal(variables, this.variables)) {
@@ -4161,11 +4179,11 @@ var QueryInfo = (function () {
4161
4179
  QueryInfo.prototype.markResult = function (result, options, allowCacheWrite) {
4162
4180
  var _this = this;
4163
4181
  this.graphQLErrors = isNonEmptyArray(result.errors) ? result.errors : [];
4164
- cancelNotifyTimeout(this);
4182
+ this.reset();
4165
4183
  if (options.fetchPolicy === 'no-cache') {
4166
4184
  this.diff = { result: result.data, complete: true };
4167
4185
  }
4168
- else if (allowCacheWrite) {
4186
+ else if (!this.stopped && allowCacheWrite) {
4169
4187
  if (shouldWriteResult(result, options.errorPolicy)) {
4170
4188
  this.cache.performTransaction(function (cache) {
4171
4189
  if (_this.shouldWrite(result, options.variables)) {
@@ -4213,7 +4231,7 @@ var QueryInfo = (function () {
4213
4231
  QueryInfo.prototype.markError = function (error) {
4214
4232
  this.networkStatus = exports.NetworkStatus.error;
4215
4233
  this.lastWrite = void 0;
4216
- cancelNotifyTimeout(this);
4234
+ this.reset();
4217
4235
  if (error.graphQLErrors) {
4218
4236
  this.graphQLErrors = error.graphQLErrors;
4219
4237
  }
@@ -5818,24 +5836,20 @@ function useBaseQuery(query, options, lazy) {
5818
5836
  var _a = React.useReducer(function (x) { return x + 1; }, 0), tick = _a[0], forceUpdate = _a[1];
5819
5837
  var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { query: query }) : { query: query };
5820
5838
  var queryDataRef = React.useRef();
5821
- var queryData = queryDataRef.current ||
5822
- new QueryData({
5823
- options: updatedOptions,
5824
- context: context,
5825
- onNewData: function () {
5826
- if (!queryData.ssrInitiated()) {
5827
- Promise.resolve().then(forceUpdate);
5828
- }
5829
- else {
5830
- forceUpdate();
5831
- }
5839
+ var queryData = queryDataRef.current || (queryDataRef.current = new QueryData({
5840
+ options: updatedOptions,
5841
+ context: context,
5842
+ onNewData: function () {
5843
+ if (!queryData.ssrInitiated()) {
5844
+ Promise.resolve().then(function () { return queryDataRef.current && forceUpdate(); });
5832
5845
  }
5833
- });
5846
+ else {
5847
+ forceUpdate();
5848
+ }
5849
+ }
5850
+ }));
5834
5851
  queryData.setOptions(updatedOptions);
5835
5852
  queryData.context = context;
5836
- if (queryData.ssrInitiated() && !queryDataRef.current) {
5837
- queryDataRef.current = queryData;
5838
- }
5839
5853
  var memo = {
5840
5854
  options: tslib.__assign(tslib.__assign({}, updatedOptions), { onError: undefined, onCompleted: undefined }),
5841
5855
  context: context,
@@ -5846,9 +5860,6 @@ function useBaseQuery(query, options, lazy) {
5846
5860
  ? result[1]
5847
5861
  : result;
5848
5862
  React.useEffect(function () {
5849
- if (!queryDataRef.current) {
5850
- queryDataRef.current = queryData;
5851
- }
5852
5863
  return function () { return queryData.cleanup(); };
5853
5864
  }, []);
5854
5865
  React.useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
@@ -5923,6 +5934,9 @@ function useReactiveVar(rv) {
5923
5934
  var value = rv();
5924
5935
  var _a = React.useState(value), setValue = _a[1];
5925
5936
  React.useEffect(function () { return rv.onNextChange(setValue); }, [value]);
5937
+ React.useEffect(function () {
5938
+ setValue(rv());
5939
+ }, []);
5926
5940
  return value;
5927
5941
  }
5928
5942