@apollo/client 3.4.7 → 3.4.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 (227) hide show
  1. package/README.md +2 -2
  2. package/apollo-client.cjs.js +155 -156
  3. package/apollo-client.cjs.js.map +1 -1
  4. package/apollo-core.cjs.js +140 -103
  5. package/apollo-core.cjs.js.map +1 -1
  6. package/apollo-core.cjs.min.js +1 -1
  7. package/cache/cache.cjs.js +29 -28
  8. package/cache/cache.cjs.js.map +1 -1
  9. package/cache/index.d.ts +1 -0
  10. package/cache/index.d.ts.map +1 -1
  11. package/cache/index.js +1 -3
  12. package/cache/index.js.map +1 -1
  13. package/cache/inmemory/entityStore.js +2 -2
  14. package/cache/inmemory/entityStore.js.map +1 -1
  15. package/cache/inmemory/object-canon.d.ts +1 -0
  16. package/cache/inmemory/object-canon.d.ts.map +1 -1
  17. package/cache/inmemory/object-canon.js +1 -0
  18. package/cache/inmemory/object-canon.js.map +1 -1
  19. package/cache/inmemory/policies.d.ts.map +1 -1
  20. package/cache/inmemory/policies.js +13 -10
  21. package/cache/inmemory/policies.js.map +1 -1
  22. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  23. package/cache/inmemory/readFromStore.js +4 -4
  24. package/cache/inmemory/readFromStore.js.map +1 -1
  25. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  26. package/cache/inmemory/writeToStore.js +2 -2
  27. package/cache/inmemory/writeToStore.js.map +1 -1
  28. package/core/ApolloClient.d.ts.map +1 -1
  29. package/core/ApolloClient.js +3 -3
  30. package/core/ApolloClient.js.map +1 -1
  31. package/core/LocalState.d.ts.map +1 -1
  32. package/core/LocalState.js +2 -2
  33. package/core/LocalState.js.map +1 -1
  34. package/core/ObservableQuery.d.ts +7 -6
  35. package/core/ObservableQuery.d.ts.map +1 -1
  36. package/core/ObservableQuery.js +79 -46
  37. package/core/ObservableQuery.js.map +1 -1
  38. package/core/QueryManager.d.ts.map +1 -1
  39. package/core/QueryManager.js +10 -10
  40. package/core/QueryManager.js.map +1 -1
  41. package/core/core.cjs.js +109 -75
  42. package/core/core.cjs.js.map +1 -1
  43. package/core/index.js +1 -1
  44. package/core/index.js.map +1 -1
  45. package/errors/errors.cjs.js +1 -2
  46. package/errors/errors.cjs.js.map +1 -1
  47. package/errors/index.d.ts +1 -0
  48. package/errors/index.d.ts.map +1 -1
  49. package/errors/index.js +1 -3
  50. package/errors/index.js.map +1 -1
  51. package/invariantErrorCodes.js +56 -81
  52. package/link/core/ApolloLink.js +2 -2
  53. package/link/core/ApolloLink.js.map +1 -1
  54. package/link/core/core.cjs.js +4 -6
  55. package/link/core/core.cjs.js.map +1 -1
  56. package/link/core/index.d.ts +1 -0
  57. package/link/core/index.d.ts.map +1 -1
  58. package/link/core/index.js +1 -3
  59. package/link/core/index.js.map +1 -1
  60. package/link/http/checkFetcher.js +2 -2
  61. package/link/http/checkFetcher.js.map +1 -1
  62. package/link/http/createHttpLink.d.ts +1 -0
  63. package/link/http/createHttpLink.d.ts.map +1 -1
  64. package/link/http/createHttpLink.js +1 -0
  65. package/link/http/createHttpLink.js.map +1 -1
  66. package/link/http/http.cjs.js +3 -3
  67. package/link/http/http.cjs.js.map +1 -1
  68. package/link/http/index.d.ts +1 -0
  69. package/link/http/index.d.ts.map +1 -1
  70. package/link/http/index.js +1 -0
  71. package/link/http/index.js.map +1 -1
  72. package/link/http/serializeFetchParameter.d.ts +1 -1
  73. package/link/http/serializeFetchParameter.d.ts.map +1 -1
  74. package/link/http/serializeFetchParameter.js +2 -2
  75. package/link/http/serializeFetchParameter.js.map +1 -1
  76. package/link/persisted-queries/index.d.ts +1 -1
  77. package/link/persisted-queries/index.d.ts.map +1 -1
  78. package/link/persisted-queries/index.js +4 -4
  79. package/link/persisted-queries/index.js.map +1 -1
  80. package/link/persisted-queries/persisted-queries.cjs.js +8 -5
  81. package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
  82. package/link/utils/index.d.ts +1 -0
  83. package/link/utils/index.d.ts.map +1 -1
  84. package/link/utils/index.js +1 -0
  85. package/link/utils/index.js.map +1 -1
  86. package/link/utils/toPromise.d.ts.map +1 -1
  87. package/link/utils/toPromise.js +1 -1
  88. package/link/utils/toPromise.js.map +1 -1
  89. package/link/utils/utils.cjs.js +3 -3
  90. package/link/utils/utils.cjs.js.map +1 -1
  91. package/link/utils/validateOperation.d.ts.map +1 -1
  92. package/link/utils/validateOperation.js +2 -2
  93. package/link/utils/validateOperation.js.map +1 -1
  94. package/package.json +11 -11
  95. package/react/context/ApolloConsumer.d.ts.map +1 -1
  96. package/react/context/ApolloConsumer.js +2 -2
  97. package/react/context/ApolloConsumer.js.map +1 -1
  98. package/react/context/ApolloProvider.d.ts.map +1 -1
  99. package/react/context/ApolloProvider.js +2 -2
  100. package/react/context/ApolloProvider.js.map +1 -1
  101. package/react/context/context.cjs.js +5 -5
  102. package/react/context/context.cjs.js.map +1 -1
  103. package/react/context/index.d.ts +1 -0
  104. package/react/context/index.d.ts.map +1 -1
  105. package/react/context/index.js +1 -0
  106. package/react/context/index.js.map +1 -1
  107. package/react/data/OperationData.d.ts.map +1 -1
  108. package/react/data/OperationData.js +3 -3
  109. package/react/data/OperationData.js.map +1 -1
  110. package/react/data/QueryData.d.ts.map +1 -1
  111. package/react/data/QueryData.js +9 -11
  112. package/react/data/QueryData.js.map +1 -1
  113. package/react/data/data.cjs.js +14 -16
  114. package/react/data/data.cjs.js.map +1 -1
  115. package/react/data/index.d.ts +1 -0
  116. package/react/data/index.d.ts.map +1 -1
  117. package/react/data/index.js +1 -0
  118. package/react/data/index.js.map +1 -1
  119. package/react/hoc/hoc-utils.d.ts.map +1 -1
  120. package/react/hoc/hoc-utils.js +2 -2
  121. package/react/hoc/hoc-utils.js.map +1 -1
  122. package/react/hoc/hoc.cjs.js +5 -5
  123. package/react/hoc/hoc.cjs.js.map +1 -1
  124. package/react/hoc/index.d.ts +1 -0
  125. package/react/hoc/index.d.ts.map +1 -1
  126. package/react/hoc/index.js +1 -0
  127. package/react/hoc/index.js.map +1 -1
  128. package/react/hoc/withApollo.d.ts.map +1 -1
  129. package/react/hoc/withApollo.js +2 -2
  130. package/react/hoc/withApollo.js.map +1 -1
  131. package/react/hooks/hooks.cjs.js +3 -3
  132. package/react/hooks/hooks.cjs.js.map +1 -1
  133. package/react/hooks/index.d.ts +1 -0
  134. package/react/hooks/index.d.ts.map +1 -1
  135. package/react/hooks/index.js +1 -0
  136. package/react/hooks/index.js.map +1 -1
  137. package/react/hooks/useApolloClient.d.ts.map +1 -1
  138. package/react/hooks/useApolloClient.js +2 -2
  139. package/react/hooks/useApolloClient.js.map +1 -1
  140. package/react/hooks/useSubscription.d.ts +1 -0
  141. package/react/hooks/useSubscription.d.ts.map +1 -1
  142. package/react/hooks/useSubscription.js +1 -0
  143. package/react/hooks/useSubscription.js.map +1 -1
  144. package/react/hooks/utils/useAfterFastRefresh.d.ts +1 -0
  145. package/react/hooks/utils/useAfterFastRefresh.d.ts.map +1 -1
  146. package/react/hooks/utils/useAfterFastRefresh.js +1 -0
  147. package/react/hooks/utils/useAfterFastRefresh.js.map +1 -1
  148. package/react/hooks/utils/useBaseQuery.d.ts +1 -0
  149. package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
  150. package/react/hooks/utils/useBaseQuery.js +1 -0
  151. package/react/hooks/utils/useBaseQuery.js.map +1 -1
  152. package/react/index.d.ts +1 -0
  153. package/react/index.d.ts.map +1 -1
  154. package/react/index.js +1 -3
  155. package/react/index.js.map +1 -1
  156. package/react/parser/index.d.ts.map +1 -1
  157. package/react/parser/index.js +5 -5
  158. package/react/parser/index.js.map +1 -1
  159. package/react/parser/parser.cjs.js +10 -10
  160. package/react/parser/parser.cjs.js.map +1 -1
  161. package/react/react.cjs.js +2 -3
  162. package/react/react.cjs.js.map +1 -1
  163. package/testing/index.d.ts +1 -0
  164. package/testing/index.d.ts.map +1 -1
  165. package/testing/index.js +1 -3
  166. package/testing/index.js.map +1 -1
  167. package/testing/testing.cjs.js +3 -5
  168. package/testing/testing.cjs.js.map +1 -1
  169. package/utilities/common/mergeDeep.js +1 -1
  170. package/utilities/common/mergeDeep.js.map +1 -1
  171. package/utilities/globals/DEV.js +2 -2
  172. package/utilities/globals/DEV.js.map +1 -1
  173. package/utilities/{common → globals}/global.d.ts +0 -0
  174. package/utilities/globals/global.d.ts.map +1 -0
  175. package/utilities/{common → globals}/global.js +0 -0
  176. package/utilities/globals/global.js.map +1 -0
  177. package/utilities/globals/globals.cjs.js +57 -0
  178. package/utilities/globals/globals.cjs.js.map +1 -0
  179. package/utilities/globals/index.d.ts +5 -2
  180. package/utilities/globals/index.d.ts.map +1 -1
  181. package/utilities/globals/index.js +8 -1
  182. package/utilities/globals/index.js.map +1 -1
  183. package/utilities/{common → globals}/maybe.d.ts +0 -0
  184. package/utilities/globals/maybe.d.ts.map +1 -0
  185. package/utilities/{common → globals}/maybe.js +0 -0
  186. package/utilities/globals/maybe.js.map +1 -0
  187. package/utilities/globals/package.json +7 -0
  188. package/utilities/graphql/directives.d.ts.map +1 -1
  189. package/utilities/graphql/directives.js +5 -5
  190. package/utilities/graphql/directives.js.map +1 -1
  191. package/utilities/graphql/fragments.d.ts.map +1 -1
  192. package/utilities/graphql/fragments.js +5 -5
  193. package/utilities/graphql/fragments.js.map +1 -1
  194. package/utilities/graphql/getFromAST.d.ts.map +1 -1
  195. package/utilities/graphql/getFromAST.js +9 -9
  196. package/utilities/graphql/getFromAST.js.map +1 -1
  197. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  198. package/utilities/graphql/storeUtils.js +2 -2
  199. package/utilities/graphql/storeUtils.js.map +1 -1
  200. package/utilities/graphql/transform.d.ts.map +1 -1
  201. package/utilities/graphql/transform.js +2 -2
  202. package/utilities/graphql/transform.js.map +1 -1
  203. package/utilities/index.d.ts +1 -3
  204. package/utilities/index.d.ts.map +1 -1
  205. package/utilities/index.js +1 -5
  206. package/utilities/index.js.map +1 -1
  207. package/utilities/observables/Concast.js +1 -1
  208. package/utilities/observables/Concast.js.map +1 -1
  209. package/utilities/package.json +1 -3
  210. package/utilities/policies/pagination.js +2 -2
  211. package/utilities/policies/pagination.js.map +1 -1
  212. package/utilities/testing/mocking/mockFetch.js +1 -1
  213. package/utilities/testing/mocking/mockFetch.js.map +1 -1
  214. package/utilities/testing/mocking/mockLink.d.ts.map +1 -1
  215. package/utilities/testing/mocking/mockLink.js +2 -2
  216. package/utilities/testing/mocking/mockLink.js.map +1 -1
  217. package/utilities/testing/mocking/mockWatchQuery.js +1 -1
  218. package/utilities/testing/mocking/mockWatchQuery.js.map +1 -1
  219. package/utilities/testing/observableToPromise.js +1 -1
  220. package/utilities/testing/observableToPromise.js.map +1 -1
  221. package/utilities/utilities.cjs.js +30 -71
  222. package/utilities/utilities.cjs.js.map +1 -1
  223. package/version.js +1 -1
  224. package/utilities/common/global.d.ts.map +0 -1
  225. package/utilities/common/global.js.map +0 -1
  226. package/utilities/common/maybe.d.ts.map +0 -1
  227. package/utilities/common/maybe.js.map +0 -1
package/core/core.cjs.js CHANGED
@@ -2,19 +2,20 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var utilities = require('../utilities');
5
+ var globals = require('../utilities/globals');
6
6
  var tslib = require('tslib');
7
- var tsInvariant = require('ts-invariant');
8
7
  var core = require('../link/core');
8
+ var utilities = require('../utilities');
9
9
  var http = require('../link/http');
10
10
  var equality = require('@wry/equality');
11
11
  var cache = require('../cache');
12
12
  var errors = require('../errors');
13
13
  var graphql = require('graphql');
14
14
  var utils = require('../link/utils');
15
+ var tsInvariant = require('ts-invariant');
15
16
  var graphqlTag = require('graphql-tag');
16
17
 
17
- var version = '3.4.7';
18
+ var version = '3.4.11';
18
19
 
19
20
  exports.NetworkStatus = void 0;
20
21
  (function (NetworkStatus) {
@@ -30,6 +31,7 @@ function isNetworkRequestInFlight(networkStatus) {
30
31
  return networkStatus ? networkStatus < 7 : false;
31
32
  }
32
33
 
34
+ var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
33
35
  var warnedAboutUpdateQuery = false;
34
36
  var ObservableQuery = (function (_super) {
35
37
  tslib.__extends(ObservableQuery, _super);
@@ -45,11 +47,12 @@ var ObservableQuery = (function (_super) {
45
47
  catch (_a) { }
46
48
  var first = !_this.observers.size;
47
49
  _this.observers.add(observer);
48
- if (_this.lastError) {
49
- observer.error && observer.error(_this.lastError);
50
+ var last = _this.last;
51
+ if (last && last.error) {
52
+ observer.error && observer.error(last.error);
50
53
  }
51
- else if (_this.lastResult) {
52
- observer.next && observer.next(_this.lastResult);
54
+ else if (last && last.result) {
55
+ observer.next && observer.next(last.result);
53
56
  }
54
57
  if (first) {
55
58
  _this.reobserve().catch(function () { });
@@ -62,18 +65,6 @@ var ObservableQuery = (function (_super) {
62
65
  }) || this;
63
66
  _this.observers = new Set();
64
67
  _this.subscriptions = new Set();
65
- _this.observer = {
66
- next: function (result) {
67
- if (_this.lastError || _this.isDifferentFromLastResult(result)) {
68
- _this.updateLastResult(result);
69
- utilities.iterateObserversSafely(_this.observers, 'next', result);
70
- }
71
- },
72
- error: function (error) {
73
- _this.updateLastResult(tslib.__assign(tslib.__assign({}, _this.lastResult), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false }));
74
- utilities.iterateObserversSafely(_this.observers, 'error', _this.lastError = error);
75
- },
76
- };
77
68
  _this.isTornDown = false;
78
69
  _this.options = options;
79
70
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
@@ -112,15 +103,24 @@ var ObservableQuery = (function (_super) {
112
103
  };
113
104
  ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
114
105
  if (saveAsLastResult === void 0) { saveAsLastResult = true; }
115
- var _a = this, lastResult = _a.lastResult, _b = _a.options.fetchPolicy, fetchPolicy = _b === void 0 ? "cache-first" : _b;
106
+ var lastResult = this.getLastResult(true);
116
107
  var networkStatus = this.queryInfo.networkStatus ||
117
108
  (lastResult && lastResult.networkStatus) ||
118
109
  exports.NetworkStatus.ready;
119
110
  var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
120
- if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {
111
+ var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
112
+ var shouldReturnCachedData = lastResult || (fetchPolicy !== 'network-only' &&
113
+ fetchPolicy !== 'no-cache' &&
114
+ fetchPolicy !== 'standby');
115
+ if (shouldReturnCachedData &&
116
+ !this.queryManager.transform(this.options.query).hasForcedResolvers) {
121
117
  var diff = this.queryInfo.getDiff();
122
- result.data = (diff.complete ||
123
- this.options.returnPartialData) ? diff.result : void 0;
118
+ if (diff.complete || this.options.returnPartialData) {
119
+ result.data = diff.result;
120
+ }
121
+ if (equality.equal(result.data, {})) {
122
+ result.data = void 0;
123
+ }
124
124
  if (diff.complete) {
125
125
  if (result.networkStatus === exports.NetworkStatus.loading &&
126
126
  (fetchPolicy === 'cache-first' ||
@@ -148,24 +148,31 @@ var ObservableQuery = (function (_super) {
148
148
  return result;
149
149
  };
150
150
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
151
- return !equality.equal(this.lastResultSnapshot, newResult);
151
+ return !this.last || !equality.equal(this.last.result, newResult);
152
152
  };
153
- ObservableQuery.prototype.getLastResult = function () {
154
- return this.lastResult;
153
+ ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
154
+ var last = this.last;
155
+ if (last &&
156
+ last[key] &&
157
+ (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
158
+ return last[key];
159
+ }
160
+ };
161
+ ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
162
+ return this.getLast("result", variablesMustMatch);
155
163
  };
156
- ObservableQuery.prototype.getLastError = function () {
157
- return this.lastError;
164
+ ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
165
+ return this.getLast("error", variablesMustMatch);
158
166
  };
159
167
  ObservableQuery.prototype.resetLastResults = function () {
160
- delete this.lastResult;
161
- delete this.lastResultSnapshot;
162
- delete this.lastError;
168
+ delete this.last;
163
169
  this.isTornDown = false;
164
170
  };
165
171
  ObservableQuery.prototype.resetQueryStoreErrors = function () {
166
172
  this.queryManager.resetErrors(this.queryId);
167
173
  };
168
174
  ObservableQuery.prototype.refetch = function (variables) {
175
+ var _a;
169
176
  var reobserveOptions = {
170
177
  pollInterval: 0,
171
178
  };
@@ -176,6 +183,13 @@ var ObservableQuery = (function (_super) {
176
183
  else if (fetchPolicy !== 'cache-and-network') {
177
184
  reobserveOptions.fetchPolicy = 'network-only';
178
185
  }
186
+ if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
187
+ var queryDef = utilities.getQueryDefinition(this.options.query);
188
+ var vars = queryDef.variableDefinitions;
189
+ if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
190
+ __DEV__ && globals.invariant.warn("Called refetch(" + JSON.stringify(variables) + ") for query " + (((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef)) + ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?");
191
+ }
192
+ }
179
193
  if (variables && !equality.equal(this.options.variables, variables)) {
180
194
  reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
181
195
  }
@@ -196,7 +210,7 @@ var ObservableQuery = (function (_super) {
196
210
  if (updateQuery) {
197
211
  if (__DEV__ &&
198
212
  !warnedAboutUpdateQuery) {
199
- __DEV__ && tsInvariant.invariant.warn("The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.");
213
+ __DEV__ && globals.invariant.warn("The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.");
200
214
  warnedAboutUpdateQuery = true;
201
215
  }
202
216
  _this.updateQuery(function (previous) { return updateQuery(previous, {
@@ -243,7 +257,7 @@ var ObservableQuery = (function (_super) {
243
257
  options.onError(err);
244
258
  return;
245
259
  }
246
- __DEV__ && tsInvariant.invariant.error('Unhandled GraphQL subscription error', err);
260
+ __DEV__ && globals.invariant.error('Unhandled GraphQL subscription error', err);
247
261
  },
248
262
  });
249
263
  this.subscriptions.add(subscription);
@@ -272,12 +286,10 @@ var ObservableQuery = (function (_super) {
272
286
  }, exports.NetworkStatus.setVariables);
273
287
  };
274
288
  ObservableQuery.prototype.updateQuery = function (mapFn) {
275
- var _a;
276
289
  var queryManager = this.queryManager;
277
290
  var result = queryManager.cache.diff({
278
291
  query: this.options.query,
279
292
  variables: this.variables,
280
- previousResult: (_a = this.lastResult) === null || _a === void 0 ? void 0 : _a.data,
281
293
  returnPartialData: true,
282
294
  optimistic: false,
283
295
  }).result;
@@ -322,7 +334,7 @@ var ObservableQuery = (function (_super) {
322
334
  pollingInfo.interval === pollInterval) {
323
335
  return;
324
336
  }
325
- __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 13);
337
+ __DEV__ ? globals.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : globals.invariant(pollInterval, 12);
326
338
  var info = pollingInfo || (this.pollingInfo = {});
327
339
  info.interval = pollInterval;
328
340
  var maybeFetch = function () {
@@ -346,18 +358,18 @@ var ObservableQuery = (function (_super) {
346
358
  };
347
359
  poll();
348
360
  };
349
- ObservableQuery.prototype.updateLastResult = function (newResult) {
350
- var previousResult = this.lastResult;
351
- this.lastResult = newResult;
352
- this.lastResultSnapshot = this.queryManager.assumeImmutableResults
353
- ? newResult
354
- : utilities.cloneDeep(newResult);
361
+ ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
362
+ if (variables === void 0) { variables = this.variables; }
363
+ this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
364
+ ? newResult
365
+ : utilities.cloneDeep(newResult), variables: variables });
355
366
  if (!utilities.isNonEmptyArray(newResult.errors)) {
356
- delete this.lastError;
367
+ delete this.last.error;
357
368
  }
358
- return previousResult;
369
+ return this.last;
359
370
  };
360
371
  ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
372
+ var _this = this;
361
373
  this.isTornDown = false;
362
374
  var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
363
375
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
@@ -365,7 +377,7 @@ var ObservableQuery = (function (_super) {
365
377
  var oldVariables = this.options.variables;
366
378
  var options = useDisposableConcast
367
379
  ? utilities.compact(this.options, newOptions)
368
- : Object.assign(this.options, utilities.compact(newOptions));
380
+ : assign(this.options, utilities.compact(newOptions));
369
381
  if (!useDisposableConcast) {
370
382
  this.updatePolling();
371
383
  if (newOptions &&
@@ -378,18 +390,39 @@ var ObservableQuery = (function (_super) {
378
390
  }
379
391
  }
380
392
  }
393
+ var variables = options.variables && tslib.__assign({}, options.variables);
381
394
  var concast = this.fetch(options, newNetworkStatus);
395
+ var observer = {
396
+ next: function (result) {
397
+ _this.reportResult(result, variables);
398
+ },
399
+ error: function (error) {
400
+ _this.reportError(error, variables);
401
+ },
402
+ };
382
403
  if (!useDisposableConcast) {
383
- if (this.concast) {
404
+ if (this.concast && this.observer) {
384
405
  this.concast.removeObserver(this.observer, true);
385
406
  }
386
407
  this.concast = concast;
408
+ this.observer = observer;
387
409
  }
388
- concast.addObserver(this.observer);
410
+ concast.addObserver(observer);
389
411
  return concast.promise;
390
412
  };
391
413
  ObservableQuery.prototype.observe = function () {
392
- this.observer.next(this.getCurrentResult(false));
414
+ this.reportResult(this.getCurrentResult(false), this.variables);
415
+ };
416
+ ObservableQuery.prototype.reportResult = function (result, variables) {
417
+ if (this.getLastError() || this.isDifferentFromLastResult(result)) {
418
+ this.updateLastResult(result, variables);
419
+ utilities.iterateObserversSafely(this.observers, 'next', result);
420
+ }
421
+ };
422
+ ObservableQuery.prototype.reportError = function (error, variables) {
423
+ var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
424
+ this.updateLastResult(errorResult, variables);
425
+ utilities.iterateObserversSafely(this.observers, 'error', this.last.error = error);
393
426
  };
394
427
  ObservableQuery.prototype.hasObservers = function () {
395
428
  return this.observers.size > 0;
@@ -397,9 +430,10 @@ var ObservableQuery = (function (_super) {
397
430
  ObservableQuery.prototype.tearDownQuery = function () {
398
431
  if (this.isTornDown)
399
432
  return;
400
- if (this.concast) {
433
+ if (this.concast && this.observer) {
401
434
  this.concast.removeObserver(this.observer);
402
435
  delete this.concast;
436
+ delete this.observer;
403
437
  }
404
438
  this.stopPolling();
405
439
  this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
@@ -412,11 +446,11 @@ var ObservableQuery = (function (_super) {
412
446
  }(utilities.Observable));
413
447
  utilities.fixObservableSubclass(ObservableQuery);
414
448
  function defaultSubscriptionObserverErrorCallback(error) {
415
- __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
449
+ __DEV__ && globals.invariant.error('Unhandled error', error.message, error.stack);
416
450
  }
417
451
  function logMissingFieldErrors(missing) {
418
452
  if (__DEV__ && utilities.isNonEmptyArray(missing)) {
419
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
453
+ __DEV__ && globals.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
420
454
  }
421
455
  }
422
456
  function applyNextFetchPolicy(options) {
@@ -597,7 +631,7 @@ var LocalState = (function () {
597
631
  }
598
632
  else {
599
633
  fragment = fragmentMap[selection.name.value];
600
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 12);
634
+ __DEV__ ? globals.invariant(fragment, "No fragment named " + selection.name.value) : globals.invariant(fragment, 11);
601
635
  }
602
636
  if (fragment && fragment.typeCondition) {
603
637
  typeCondition = fragment.typeCondition.name.value;
@@ -983,7 +1017,7 @@ var QueryManager = (function () {
983
1017
  this.queries.forEach(function (_info, queryId) {
984
1018
  _this.stopQueryNoBroadcast(queryId);
985
1019
  });
986
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(14));
1020
+ this.cancelPendingFetches(__DEV__ ? new globals.InvariantError('QueryManager stopped while query was in flight') : new globals.InvariantError(13));
987
1021
  };
988
1022
  QueryManager.prototype.cancelPendingFetches = function (error) {
989
1023
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -996,10 +1030,10 @@ var QueryManager = (function () {
996
1030
  return tslib.__generator(this, function (_f) {
997
1031
  switch (_f.label) {
998
1032
  case 0:
999
- __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 15);
1000
- __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
1001
- fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : tsInvariant.invariant(fetchPolicy === 'network-only' ||
1002
- fetchPolicy === 'no-cache', 16);
1033
+ __DEV__ ? globals.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : globals.invariant(mutation, 14);
1034
+ __DEV__ ? globals.invariant(fetchPolicy === 'network-only' ||
1035
+ fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : globals.invariant(fetchPolicy === 'network-only' ||
1036
+ fetchPolicy === 'no-cache', 15);
1003
1037
  mutationId = this.generateMutationId();
1004
1038
  mutation = this.transform(mutation).document;
1005
1039
  variables = this.getVariables(mutation, variables);
@@ -1198,7 +1232,7 @@ var QueryManager = (function () {
1198
1232
  _this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
1199
1233
  }
1200
1234
  catch (error) {
1201
- __DEV__ && tsInvariant.invariant.error(error);
1235
+ __DEV__ && globals.invariant.error(error);
1202
1236
  }
1203
1237
  }, mutation.mutationId);
1204
1238
  };
@@ -1283,11 +1317,11 @@ var QueryManager = (function () {
1283
1317
  QueryManager.prototype.query = function (options, queryId) {
1284
1318
  var _this = this;
1285
1319
  if (queryId === void 0) { queryId = this.generateQueryId(); }
1286
- __DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
1287
- 'in the query option.') : tsInvariant.invariant(options.query, 17);
1288
- __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 18);
1289
- __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 19);
1290
- __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 20);
1320
+ __DEV__ ? globals.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
1321
+ 'in the query option.') : globals.invariant(options.query, 16);
1322
+ __DEV__ ? globals.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : globals.invariant(options.query.kind === 'Document', 17);
1323
+ __DEV__ ? globals.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : globals.invariant(!options.returnPartialData, 18);
1324
+ __DEV__ ? globals.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : globals.invariant(!options.pollInterval, 19);
1291
1325
  return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
1292
1326
  };
1293
1327
  QueryManager.prototype.generateQueryId = function () {
@@ -1309,7 +1343,7 @@ var QueryManager = (function () {
1309
1343
  queryInfo.stop();
1310
1344
  };
1311
1345
  QueryManager.prototype.clearStore = function () {
1312
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(21));
1346
+ this.cancelPendingFetches(__DEV__ ? new globals.InvariantError('Store reset while query was in flight (not completed in link chain)') : new globals.InvariantError(20));
1313
1347
  this.queries.forEach(function (queryInfo) {
1314
1348
  if (queryInfo.observableQuery) {
1315
1349
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -1382,7 +1416,7 @@ var QueryManager = (function () {
1382
1416
  queryInfo: queryInfo,
1383
1417
  options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
1384
1418
  });
1385
- tsInvariant.invariant(oq.queryId === queryId);
1419
+ globals.invariant(oq.queryId === queryId);
1386
1420
  queryInfo.setObservableQuery(oq);
1387
1421
  queries.set(queryId, oq);
1388
1422
  });
@@ -1390,7 +1424,7 @@ var QueryManager = (function () {
1390
1424
  if (__DEV__ && queryNamesAndDocs.size) {
1391
1425
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
1392
1426
  if (!included) {
1393
- __DEV__ && tsInvariant.invariant.warn("Unknown query " + (typeof nameOrDoc === "string" ? "named " : "") + JSON.stringify(nameOrDoc, null, 2) + " requested in refetchQueries options.include array");
1427
+ __DEV__ && globals.invariant.warn("Unknown query " + (typeof nameOrDoc === "string" ? "named " : "") + JSON.stringify(nameOrDoc, null, 2) + " requested in refetchQueries options.include array");
1394
1428
  }
1395
1429
  });
1396
1430
  }
@@ -1584,7 +1618,7 @@ var QueryManager = (function () {
1584
1618
  return _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
1585
1619
  };
1586
1620
  this.fetchCancelFns.set(queryId, function (reason) {
1587
- Promise.resolve().then(function () { return concast.cancel(reason); });
1621
+ setTimeout(function () { return concast.cancel(reason); });
1588
1622
  });
1589
1623
  var concast = new utilities.Concast(this.transform(normalized.query).hasClientExports
1590
1624
  ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
@@ -1800,9 +1834,9 @@ var ApolloClient = (function () {
1800
1834
  : core.ApolloLink.empty();
1801
1835
  }
1802
1836
  if (!cache) {
1803
- throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
1837
+ throw __DEV__ ? new globals.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
1804
1838
  "in the options object. \n" +
1805
- "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(10);
1839
+ "For more information, please visit: https://go.apollo.dev/c/docs") : new globals.InvariantError(9);
1806
1840
  }
1807
1841
  this.link = link;
1808
1842
  this.cache = cache;
@@ -1840,7 +1874,7 @@ var ApolloClient = (function () {
1840
1874
  }
1841
1875
  }
1842
1876
  if (url) {
1843
- __DEV__ && tsInvariant.invariant.log("Download the Apollo DevTools for a better development " +
1877
+ __DEV__ && globals.invariant.log("Download the Apollo DevTools for a better development " +
1844
1878
  "experience: " + url);
1845
1879
  }
1846
1880
  }
@@ -1895,10 +1929,10 @@ var ApolloClient = (function () {
1895
1929
  if (this.defaultOptions.query) {
1896
1930
  options = mergeOptions(this.defaultOptions.query, options);
1897
1931
  }
1898
- __DEV__ ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
1932
+ __DEV__ ? globals.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
1899
1933
  'client.query can only return a single result. Please use client.watchQuery ' +
1900
1934
  'to receive multiple results from the cache and the network, or consider ' +
1901
- 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 11);
1935
+ 'using a different fetchPolicy, such as cache-first or network-only.') : globals.invariant(options.fetchPolicy !== 'cache-and-network', 10);
1902
1936
  if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
1903
1937
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
1904
1938
  }
@@ -1977,7 +2011,7 @@ var ApolloClient = (function () {
1977
2011
  result.queries = queries;
1978
2012
  result.results = results;
1979
2013
  result.catch(function (error) {
1980
- __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
2014
+ __DEV__ && globals.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
1981
2015
  });
1982
2016
  return result;
1983
2017
  };
@@ -2009,12 +2043,11 @@ var ApolloClient = (function () {
2009
2043
  return ApolloClient;
2010
2044
  }());
2011
2045
 
2012
- tsInvariant.setVerbosity(utilities.DEV ? "log" : "silent");
2046
+ tsInvariant.setVerbosity(globals.DEV ? "log" : "silent");
2013
2047
 
2014
2048
  exports.Observable = utilities.Observable;
2015
2049
  exports.isReference = utilities.isReference;
2016
2050
  exports.makeReference = utilities.makeReference;
2017
- exports.setLogVerbosity = tsInvariant.setVerbosity;
2018
2051
  exports.ApolloCache = cache.ApolloCache;
2019
2052
  exports.Cache = cache.Cache;
2020
2053
  exports.InMemoryCache = cache.InMemoryCache;
@@ -2027,6 +2060,7 @@ exports.fromError = utils.fromError;
2027
2060
  exports.fromPromise = utils.fromPromise;
2028
2061
  exports.throwServerError = utils.throwServerError;
2029
2062
  exports.toPromise = utils.toPromise;
2063
+ exports.setLogVerbosity = tsInvariant.setVerbosity;
2030
2064
  exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
2031
2065
  exports.disableFragmentWarnings = graphqlTag.disableFragmentWarnings;
2032
2066
  exports.enableExperimentalFragmentVariables = graphqlTag.enableExperimentalFragmentVariables;