@apollo/client 3.4.0-rc.7 → 3.4.1

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 (234) hide show
  1. package/apollo-client.cjs.js +300 -263
  2. package/apollo-client.cjs.js.map +1 -1
  3. package/apollo-client.cjs.min.js +1 -1
  4. package/cache/cache.cjs.js +105 -41
  5. package/cache/cache.cjs.js.map +1 -1
  6. package/cache/core/types/DataProxy.js +1 -0
  7. package/cache/index.d.ts +0 -1
  8. package/cache/index.d.ts.map +1 -1
  9. package/cache/index.js +3 -1
  10. package/cache/index.js.map +1 -1
  11. package/cache/inmemory/entityStore.d.ts +3 -2
  12. package/cache/inmemory/entityStore.d.ts.map +1 -1
  13. package/cache/inmemory/entityStore.js +22 -10
  14. package/cache/inmemory/entityStore.js.map +1 -1
  15. package/cache/inmemory/fixPolyfills.native.js +1 -0
  16. package/cache/inmemory/helpers.d.ts +1 -1
  17. package/cache/inmemory/helpers.d.ts.map +1 -1
  18. package/cache/inmemory/inMemoryCache.d.ts +5 -1
  19. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  20. package/cache/inmemory/inMemoryCache.js +24 -3
  21. package/cache/inmemory/inMemoryCache.js.map +1 -1
  22. package/cache/inmemory/object-canon.d.ts +3 -1
  23. package/cache/inmemory/object-canon.d.ts.map +1 -1
  24. package/cache/inmemory/object-canon.js +12 -7
  25. package/cache/inmemory/object-canon.js.map +1 -1
  26. package/cache/inmemory/policies.d.ts.map +1 -1
  27. package/cache/inmemory/policies.js +23 -10
  28. package/cache/inmemory/policies.js.map +1 -1
  29. package/cache/inmemory/readFromStore.d.ts +5 -2
  30. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  31. package/cache/inmemory/readFromStore.js +9 -6
  32. package/cache/inmemory/readFromStore.js.map +1 -1
  33. package/cache/inmemory/types.js +1 -0
  34. package/cache/inmemory/writeToStore.d.ts +1 -0
  35. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  36. package/cache/inmemory/writeToStore.js +16 -7
  37. package/cache/inmemory/writeToStore.js.map +1 -1
  38. package/core/ApolloClient.d.ts.map +1 -1
  39. package/core/ApolloClient.js +3 -0
  40. package/core/ApolloClient.js.map +1 -1
  41. package/core/LocalState.js +2 -4
  42. package/core/LocalState.js.map +1 -1
  43. package/core/ObservableQuery.d.ts +7 -6
  44. package/core/ObservableQuery.d.ts.map +1 -1
  45. package/core/ObservableQuery.js +116 -78
  46. package/core/ObservableQuery.js.map +1 -1
  47. package/core/QueryInfo.d.ts +0 -1
  48. package/core/QueryInfo.d.ts.map +1 -1
  49. package/core/QueryInfo.js +3 -6
  50. package/core/QueryInfo.js.map +1 -1
  51. package/core/QueryManager.d.ts +3 -3
  52. package/core/QueryManager.d.ts.map +1 -1
  53. package/core/QueryManager.js +13 -10
  54. package/core/QueryManager.js.map +1 -1
  55. package/core/core.cjs.js +137 -181
  56. package/core/core.cjs.js.map +1 -1
  57. package/core/index.d.ts +0 -1
  58. package/core/index.d.ts.map +1 -1
  59. package/core/index.js +2 -2
  60. package/core/index.js.map +1 -1
  61. package/core/types.d.ts +4 -1
  62. package/core/types.d.ts.map +1 -1
  63. package/core/types.js +1 -0
  64. package/core/types.js.map +1 -1
  65. package/core/watchQueryOptions.js +1 -0
  66. package/errors/errors.cjs.js +2 -0
  67. package/errors/errors.cjs.js.map +1 -1
  68. package/errors/index.d.ts.map +1 -1
  69. package/errors/index.js +3 -0
  70. package/errors/index.js.map +1 -1
  71. package/invariantErrorCodes.js +82 -57
  72. package/link/context/context.cjs.js +4 -0
  73. package/link/context/context.cjs.js.map +1 -1
  74. package/link/context/index.d.ts.map +1 -1
  75. package/link/context/index.js +4 -0
  76. package/link/context/index.js.map +1 -1
  77. package/link/core/ApolloLink.js +1 -1
  78. package/link/core/core.cjs.js +4 -2
  79. package/link/core/core.cjs.js.map +1 -1
  80. package/link/core/index.d.ts.map +1 -1
  81. package/link/core/index.js +3 -0
  82. package/link/core/index.js.map +1 -1
  83. package/link/core/types.js +1 -0
  84. package/link/http/checkFetcher.js +1 -1
  85. package/link/http/http.cjs.js +13 -3
  86. package/link/http/http.cjs.js.map +1 -1
  87. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  88. package/link/http/selectHttpOptionsAndBody.js +11 -1
  89. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  90. package/link/http/serializeFetchParameter.js +1 -1
  91. package/link/persisted-queries/index.d.ts.map +1 -1
  92. package/link/persisted-queries/index.js +2 -2
  93. package/link/persisted-queries/persisted-queries.cjs.js +2 -2
  94. package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
  95. package/link/utils/utils.cjs.js +1 -1
  96. package/link/utils/utils.cjs.js.map +1 -1
  97. package/link/utils/validateOperation.js +1 -1
  98. package/package.json +20 -20
  99. package/react/components/Mutation.d.ts +1 -1
  100. package/react/components/Query.js +1 -1
  101. package/react/components/Query.js.map +1 -1
  102. package/react/components/components.cjs.js +45 -31
  103. package/react/components/components.cjs.js.map +1 -1
  104. package/react/components/types.js +1 -0
  105. package/react/context/ApolloConsumer.js +1 -1
  106. package/react/context/ApolloProvider.js +1 -1
  107. package/react/context/context.cjs.js +22 -8
  108. package/react/context/context.cjs.js.map +1 -1
  109. package/react/data/OperationData.js +2 -2
  110. package/react/data/QueryData.d.ts +1 -2
  111. package/react/data/QueryData.d.ts.map +1 -1
  112. package/react/data/QueryData.js +65 -72
  113. package/react/data/QueryData.js.map +1 -1
  114. package/react/data/data.cjs.js +65 -71
  115. package/react/data/data.cjs.js.map +1 -1
  116. package/react/hoc/hoc-utils.d.ts +2 -1
  117. package/react/hoc/hoc-utils.d.ts.map +1 -1
  118. package/react/hoc/hoc-utils.js +1 -1
  119. package/react/hoc/hoc.cjs.js +35 -18
  120. package/react/hoc/hoc.cjs.js.map +1 -1
  121. package/react/hoc/mutation-hoc.d.ts.map +1 -1
  122. package/react/hoc/query-hoc.d.ts.map +1 -1
  123. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  124. package/react/hoc/types.js +1 -0
  125. package/react/hoc/withApollo.js +1 -1
  126. package/react/hooks/hooks.cjs.js +56 -10
  127. package/react/hooks/hooks.cjs.js.map +1 -1
  128. package/react/hooks/useApolloClient.js +1 -1
  129. package/react/hooks/useSubscription.d.ts.map +1 -1
  130. package/react/hooks/useSubscription.js +16 -6
  131. package/react/hooks/useSubscription.js.map +1 -1
  132. package/react/hooks/utils/useAfterFastRefresh.d.ts +2 -0
  133. package/react/hooks/utils/useAfterFastRefresh.d.ts.map +1 -0
  134. package/react/hooks/utils/useAfterFastRefresh.js +18 -0
  135. package/react/hooks/utils/useAfterFastRefresh.js.map +1 -0
  136. package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
  137. package/react/hooks/utils/useBaseQuery.js +10 -3
  138. package/react/hooks/utils/useBaseQuery.js.map +1 -1
  139. package/react/index.d.ts +0 -1
  140. package/react/index.d.ts.map +1 -1
  141. package/react/index.js +3 -1
  142. package/react/index.js.map +1 -1
  143. package/react/parser/index.js +4 -4
  144. package/react/parser/parser.cjs.js +4 -4
  145. package/react/parser/parser.cjs.js.map +1 -1
  146. package/react/react.cjs.js +2 -2
  147. package/react/react.cjs.js.map +1 -1
  148. package/react/ssr/ssr.cjs.js +15 -1
  149. package/react/ssr/ssr.cjs.js.map +1 -1
  150. package/react/types/types.d.ts +9 -3
  151. package/react/types/types.d.ts.map +1 -1
  152. package/react/types/types.js +1 -0
  153. package/react/types/types.js.map +1 -1
  154. package/testing/index.d.ts.map +1 -1
  155. package/testing/index.js +3 -0
  156. package/testing/index.js.map +1 -1
  157. package/testing/testing.cjs.js +68 -17
  158. package/testing/testing.cjs.js.map +1 -1
  159. package/utilities/common/canUse.d.ts +1 -0
  160. package/utilities/common/canUse.d.ts.map +1 -1
  161. package/utilities/common/canUse.js +1 -0
  162. package/utilities/common/canUse.js.map +1 -1
  163. package/utilities/common/global.d.ts.map +1 -1
  164. package/utilities/common/mergeDeep.js +2 -2
  165. package/utilities/common/mergeDeep.js.map +1 -1
  166. package/utilities/common/stringifyForDisplay.d.ts +2 -0
  167. package/utilities/common/stringifyForDisplay.d.ts.map +1 -0
  168. package/utilities/common/stringifyForDisplay.js +8 -0
  169. package/utilities/common/stringifyForDisplay.js.map +1 -0
  170. package/utilities/globals/DEV.d.ts +3 -0
  171. package/utilities/globals/DEV.d.ts.map +1 -0
  172. package/utilities/globals/DEV.js +20 -0
  173. package/utilities/globals/DEV.js.map +1 -0
  174. package/utilities/globals/graphql.d.ts +1 -1
  175. package/utilities/globals/graphql.d.ts.map +1 -1
  176. package/utilities/globals/graphql.js +3 -3
  177. package/utilities/globals/graphql.js.map +1 -1
  178. package/utilities/globals/index.d.ts +4 -2
  179. package/utilities/globals/index.d.ts.map +1 -1
  180. package/utilities/globals/index.js +5 -4
  181. package/utilities/globals/index.js.map +1 -1
  182. package/utilities/graphql/directives.js +4 -4
  183. package/utilities/graphql/fragments.js +5 -5
  184. package/utilities/graphql/getFromAST.js +8 -8
  185. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  186. package/utilities/graphql/storeUtils.js +1 -1
  187. package/utilities/graphql/transform.js +2 -2
  188. package/utilities/graphql/transform.js.map +1 -1
  189. package/utilities/index.d.ts +3 -1
  190. package/utilities/index.d.ts.map +1 -1
  191. package/utilities/index.js +5 -1
  192. package/utilities/index.js.map +1 -1
  193. package/utilities/package.json +3 -1
  194. package/utilities/policies/pagination.d.ts.map +1 -1
  195. package/utilities/policies/pagination.js +10 -11
  196. package/utilities/policies/pagination.js.map +1 -1
  197. package/utilities/testing/index.d.ts +1 -0
  198. package/utilities/testing/index.d.ts.map +1 -1
  199. package/utilities/testing/index.js +1 -0
  200. package/utilities/testing/index.js.map +1 -1
  201. package/utilities/testing/itAsync.d.ts +5 -8
  202. package/utilities/testing/itAsync.d.ts.map +1 -1
  203. package/utilities/testing/itAsync.js +6 -7
  204. package/utilities/testing/itAsync.js.map +1 -1
  205. package/utilities/testing/mocking/mockFetch.js +2 -2
  206. package/utilities/testing/mocking/mockFetch.js.map +1 -1
  207. package/utilities/testing/mocking/mockLink.d.ts.map +1 -1
  208. package/utilities/testing/mocking/mockLink.js +2 -8
  209. package/utilities/testing/mocking/mockLink.js.map +1 -1
  210. package/utilities/testing/mocking/mockWatchQuery.d.ts.map +1 -1
  211. package/utilities/testing/mocking/mockWatchQuery.js +2 -2
  212. package/utilities/testing/mocking/mockWatchQuery.js.map +1 -1
  213. package/utilities/testing/observableToPromise.js +2 -2
  214. package/utilities/testing/observableToPromise.js.map +1 -1
  215. package/utilities/testing/withConsoleSpy.d.ts +4 -0
  216. package/utilities/testing/withConsoleSpy.d.ts.map +1 -0
  217. package/utilities/testing/withConsoleSpy.js +39 -0
  218. package/utilities/testing/withConsoleSpy.js.map +1 -0
  219. package/utilities/types/IsStrictlyAny.js +1 -0
  220. package/utilities/utilities.cjs.js +56 -48
  221. package/utilities/utilities.cjs.js.map +1 -1
  222. package/version.js +1 -1
  223. package/core/Reobserver.d.ts +0 -18
  224. package/core/Reobserver.d.ts.map +0 -1
  225. package/core/Reobserver.js +0 -87
  226. package/core/Reobserver.js.map +0 -1
  227. package/utilities/globals/__DEV__.d.ts +0 -3
  228. package/utilities/globals/__DEV__.d.ts.map +0 -1
  229. package/utilities/globals/__DEV__.js +0 -32
  230. package/utilities/globals/__DEV__.js.map +0 -1
  231. package/utilities/globals/process.d.ts +0 -2
  232. package/utilities/globals/process.d.ts.map +0 -1
  233. package/utilities/globals/process.js +0 -31
  234. package/utilities/globals/process.js.map +0 -1
package/core/core.cjs.js CHANGED
@@ -14,7 +14,7 @@ var graphql = require('graphql');
14
14
  var utils = require('../link/utils');
15
15
  var graphqlTag = require('graphql-tag');
16
16
 
17
- var version = '3.4.0-rc.7';
17
+ var version = '3.4.1';
18
18
 
19
19
  exports.NetworkStatus = void 0;
20
20
  (function (NetworkStatus) {
@@ -30,95 +30,35 @@ function isNetworkRequestInFlight(networkStatus) {
30
30
  return networkStatus ? networkStatus < 7 : false;
31
31
  }
32
32
 
33
- var Reobserver = (function () {
34
- function Reobserver(observer, options, fetch, shouldFetch) {
35
- this.observer = observer;
36
- this.options = options;
37
- this.fetch = fetch;
38
- this.shouldFetch = shouldFetch;
39
- }
40
- Reobserver.prototype.reobserve = function (newOptions, newNetworkStatus) {
41
- if (newOptions) {
42
- this.updateOptions(newOptions);
43
- }
44
- else {
45
- this.updatePolling();
46
- }
47
- var concast = this.fetch(this.options, newNetworkStatus);
48
- if (this.concast) {
49
- this.concast.removeObserver(this.observer, true);
50
- }
51
- concast.addObserver(this.observer);
52
- return (this.concast = concast).promise;
53
- };
54
- Reobserver.prototype.updateOptions = function (newOptions) {
55
- Object.assign(this.options, utilities.compact(newOptions));
56
- this.updatePolling();
57
- return this;
58
- };
59
- Reobserver.prototype.stop = function () {
60
- if (this.concast) {
61
- this.concast.removeObserver(this.observer);
62
- delete this.concast;
63
- }
64
- if (this.pollingInfo) {
65
- clearTimeout(this.pollingInfo.timeout);
66
- this.options.pollInterval = 0;
67
- this.updatePolling();
68
- }
69
- };
70
- Reobserver.prototype.updatePolling = function () {
71
- var _this = this;
72
- var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
73
- if (!pollInterval) {
74
- if (pollingInfo) {
75
- clearTimeout(pollingInfo.timeout);
76
- delete this.pollingInfo;
77
- }
78
- return;
79
- }
80
- if (pollingInfo &&
81
- pollingInfo.interval === pollInterval) {
82
- return;
83
- }
84
- __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 21);
85
- if (this.shouldFetch === false) {
86
- return;
87
- }
88
- var info = pollingInfo || (this.pollingInfo = {});
89
- info.interval = pollInterval;
90
- var maybeFetch = function () {
91
- if (_this.pollingInfo) {
92
- if (_this.shouldFetch && _this.shouldFetch()) {
93
- _this.reobserve({
94
- fetchPolicy: "network-only",
95
- nextFetchPolicy: _this.options.fetchPolicy || "cache-first",
96
- }, exports.NetworkStatus.poll).then(poll, poll);
97
- }
98
- else {
99
- poll();
100
- }
101
- }
102
- };
103
- var poll = function () {
104
- var info = _this.pollingInfo;
105
- if (info) {
106
- clearTimeout(info.timeout);
107
- info.timeout = setTimeout(maybeFetch, info.interval);
108
- }
109
- };
110
- poll();
111
- };
112
- return Reobserver;
113
- }());
114
-
115
33
  var warnedAboutUpdateQuery = false;
116
34
  var ObservableQuery = (function (_super) {
117
35
  tslib.__extends(ObservableQuery, _super);
118
36
  function ObservableQuery(_a) {
119
37
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
120
38
  var _this = _super.call(this, function (observer) {
121
- return _this.onSubscribe(observer);
39
+ try {
40
+ var subObserver = observer._subscription._observer;
41
+ if (subObserver && !subObserver.error) {
42
+ subObserver.error = defaultSubscriptionObserverErrorCallback;
43
+ }
44
+ }
45
+ catch (_a) { }
46
+ var first = !_this.observers.size;
47
+ _this.observers.add(observer);
48
+ if (_this.lastError) {
49
+ observer.error && observer.error(_this.lastError);
50
+ }
51
+ else if (_this.lastResult) {
52
+ observer.next && observer.next(_this.lastResult);
53
+ }
54
+ if (first) {
55
+ _this.reobserve().catch(function () { });
56
+ }
57
+ return function () {
58
+ if (_this.observers.delete(observer) && !_this.observers.size) {
59
+ _this.tearDownQuery();
60
+ }
61
+ };
122
62
  }) || this;
123
63
  _this.observers = new Set();
124
64
  _this.subscriptions = new Set();
@@ -139,6 +79,7 @@ var ObservableQuery = (function (_super) {
139
79
  _this.queryId = queryManager.generateQueryId();
140
80
  var opDef = utilities.getOperationDefinition(options.query);
141
81
  _this.queryName = opDef && opDef.name && opDef.name.value;
82
+ _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
142
83
  _this.queryManager = queryManager;
143
84
  _this.queryInfo = queryInfo;
144
85
  return _this;
@@ -171,21 +112,12 @@ var ObservableQuery = (function (_super) {
171
112
  };
172
113
  ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
173
114
  if (saveAsLastResult === void 0) { saveAsLastResult = true; }
174
- var lastResult = this.lastResult;
115
+ var _a = this, lastResult = _a.lastResult, _b = _a.options.fetchPolicy, fetchPolicy = _b === void 0 ? "cache-first" : _b;
175
116
  var networkStatus = this.queryInfo.networkStatus ||
176
117
  (lastResult && lastResult.networkStatus) ||
177
118
  exports.NetworkStatus.ready;
178
119
  var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
179
- if (this.isTornDown) {
180
- return result;
181
- }
182
- var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? 'cache-first' : _a;
183
- if (fetchPolicy === 'no-cache' ||
184
- fetchPolicy === 'network-only') {
185
- delete result.partial;
186
- }
187
- else if (!result.data ||
188
- !this.queryManager.transform(this.options.query).hasForcedResolvers) {
120
+ if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {
189
121
  var diff = this.queryInfo.getDiff();
190
122
  result.data = (diff.complete ||
191
123
  this.options.returnPartialData) ? diff.result : void 0;
@@ -198,7 +130,7 @@ var ObservableQuery = (function (_super) {
198
130
  }
199
131
  delete result.partial;
200
132
  }
201
- else {
133
+ else if (fetchPolicy !== "no-cache") {
202
134
  result.partial = true;
203
135
  }
204
136
  if (!diff.complete &&
@@ -237,16 +169,17 @@ var ObservableQuery = (function (_super) {
237
169
  pollInterval: 0,
238
170
  };
239
171
  var fetchPolicy = this.options.fetchPolicy;
240
- if (fetchPolicy !== 'no-cache' &&
241
- fetchPolicy !== 'cache-and-network') {
172
+ if (fetchPolicy === 'no-cache') {
173
+ reobserveOptions.fetchPolicy = 'no-cache';
174
+ }
175
+ else if (fetchPolicy !== 'cache-and-network') {
242
176
  reobserveOptions.fetchPolicy = 'network-only';
243
- reobserveOptions.nextFetchPolicy = fetchPolicy || "cache-first";
244
177
  }
245
178
  if (variables && !equality.equal(this.options.variables, variables)) {
246
179
  reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
247
180
  }
248
181
  this.queryInfo.resetLastWrite();
249
- return this.newReobserver(false).reobserve(reobserveOptions, exports.NetworkStatus.refetch);
182
+ return this.reobserve(reobserveOptions, exports.NetworkStatus.refetch);
250
183
  };
251
184
  ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
252
185
  var _this = this;
@@ -332,18 +265,10 @@ var ObservableQuery = (function (_super) {
332
265
  if (!this.observers.size) {
333
266
  return Promise.resolve();
334
267
  }
335
- var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? 'cache-first' : _a;
336
- var reobserveOptions = {
337
- fetchPolicy: fetchPolicy,
268
+ return this.reobserve({
269
+ fetchPolicy: this.initialFetchPolicy,
338
270
  variables: variables,
339
- };
340
- if (fetchPolicy !== 'cache-first' &&
341
- fetchPolicy !== 'no-cache' &&
342
- fetchPolicy !== 'network-only') {
343
- reobserveOptions.fetchPolicy = 'cache-and-network';
344
- reobserveOptions.nextFetchPolicy = fetchPolicy;
345
- }
346
- return this.reobserve(reobserveOptions, exports.NetworkStatus.setVariables);
271
+ }, exports.NetworkStatus.setVariables);
347
272
  };
348
273
  ObservableQuery.prototype.updateQuery = function (mapFn) {
349
274
  var _a;
@@ -368,12 +293,57 @@ var ObservableQuery = (function (_super) {
368
293
  }
369
294
  };
370
295
  ObservableQuery.prototype.startPolling = function (pollInterval) {
371
- this.getReobserver().updateOptions({ pollInterval: pollInterval });
296
+ this.options.pollInterval = pollInterval;
297
+ this.updatePolling();
372
298
  };
373
299
  ObservableQuery.prototype.stopPolling = function () {
374
- if (this.reobserver) {
375
- this.reobserver.updateOptions({ pollInterval: 0 });
300
+ this.options.pollInterval = 0;
301
+ this.updatePolling();
302
+ };
303
+ ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
304
+ this.queryManager.setObservableQuery(this);
305
+ return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
306
+ };
307
+ ObservableQuery.prototype.updatePolling = function () {
308
+ var _this = this;
309
+ if (this.queryManager.ssrMode) {
310
+ return;
311
+ }
312
+ var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
313
+ if (!pollInterval) {
314
+ if (pollingInfo) {
315
+ clearTimeout(pollingInfo.timeout);
316
+ delete this.pollingInfo;
317
+ }
318
+ return;
376
319
  }
320
+ if (pollingInfo &&
321
+ pollingInfo.interval === pollInterval) {
322
+ return;
323
+ }
324
+ __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 13);
325
+ var info = pollingInfo || (this.pollingInfo = {});
326
+ info.interval = pollInterval;
327
+ var maybeFetch = function () {
328
+ if (_this.pollingInfo) {
329
+ if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus)) {
330
+ _this.reobserve({
331
+ fetchPolicy: "network-only",
332
+ }, exports.NetworkStatus.poll).then(poll, poll);
333
+ }
334
+ else {
335
+ poll();
336
+ }
337
+ }
338
+ };
339
+ var poll = function () {
340
+ var info = _this.pollingInfo;
341
+ if (info) {
342
+ clearTimeout(info.timeout);
343
+ info.timeout = setTimeout(maybeFetch, info.interval);
344
+ }
345
+ };
346
+ poll();
377
347
  };
378
348
  ObservableQuery.prototype.updateLastResult = function (newResult) {
379
349
  var previousResult = this.lastResult;
@@ -386,50 +356,36 @@ var ObservableQuery = (function (_super) {
386
356
  }
387
357
  return previousResult;
388
358
  };
389
- ObservableQuery.prototype.onSubscribe = function (observer) {
390
- var _this = this;
391
- if (observer === this.observer) {
392
- return function () { };
393
- }
394
- try {
395
- var subObserver = observer._subscription._observer;
396
- if (subObserver && !subObserver.error) {
397
- subObserver.error = defaultSubscriptionObserverErrorCallback;
359
+ ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
360
+ this.isTornDown = false;
361
+ var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
362
+ newNetworkStatus === exports.NetworkStatus.fetchMore ||
363
+ newNetworkStatus === exports.NetworkStatus.poll;
364
+ var oldVariables = this.options.variables;
365
+ var options = useDisposableConcast
366
+ ? utilities.compact(this.options, newOptions)
367
+ : Object.assign(this.options, utilities.compact(newOptions));
368
+ if (!useDisposableConcast) {
369
+ this.updatePolling();
370
+ if (newOptions &&
371
+ newOptions.variables &&
372
+ !newOptions.fetchPolicy &&
373
+ !equality.equal(newOptions.variables, oldVariables)) {
374
+ options.fetchPolicy = this.initialFetchPolicy;
375
+ if (newNetworkStatus === void 0) {
376
+ newNetworkStatus = exports.NetworkStatus.setVariables;
377
+ }
398
378
  }
399
379
  }
400
- catch (_a) { }
401
- var first = !this.observers.size;
402
- this.observers.add(observer);
403
- if (this.lastError) {
404
- observer.error && observer.error(this.lastError);
405
- }
406
- else if (this.lastResult) {
407
- observer.next && observer.next(this.lastResult);
408
- }
409
- if (first) {
410
- this.reobserve().catch(function () { });
411
- }
412
- return function () {
413
- if (_this.observers.delete(observer) && !_this.observers.size) {
414
- _this.tearDownQuery();
380
+ var concast = this.fetch(options, newNetworkStatus);
381
+ if (!useDisposableConcast) {
382
+ if (this.concast) {
383
+ this.concast.removeObserver(this.observer, true);
415
384
  }
416
- };
417
- };
418
- ObservableQuery.prototype.getReobserver = function () {
419
- return this.reobserver || (this.reobserver = this.newReobserver(true));
420
- };
421
- ObservableQuery.prototype.newReobserver = function (shareOptions) {
422
- var _this = this;
423
- var _a = this, queryManager = _a.queryManager, queryId = _a.queryId;
424
- queryManager.setObservableQuery(this);
425
- return new Reobserver(this.observer, shareOptions ? this.options : tslib.__assign({}, this.options), function (currentOptions, newNetworkStatus) {
426
- queryManager.setObservableQuery(_this);
427
- return queryManager.fetchQueryObservable(queryId, currentOptions, newNetworkStatus);
428
- }, !queryManager.ssrMode && (function () { return !isNetworkRequestInFlight(_this.queryInfo.networkStatus); }));
429
- };
430
- ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
431
- this.isTornDown = false;
432
- return this.getReobserver().reobserve(newOptions, newNetworkStatus);
385
+ this.concast = concast;
386
+ }
387
+ concast.addObserver(this.observer);
388
+ return concast.promise;
433
389
  };
434
390
  ObservableQuery.prototype.observe = function () {
435
391
  this.observer.next(this.getCurrentResult(false));
@@ -440,10 +396,11 @@ var ObservableQuery = (function (_super) {
440
396
  ObservableQuery.prototype.tearDownQuery = function () {
441
397
  if (this.isTornDown)
442
398
  return;
443
- if (this.reobserver) {
444
- this.reobserver.stop();
445
- delete this.reobserver;
399
+ if (this.concast) {
400
+ this.concast.removeObserver(this.observer);
401
+ delete this.concast;
446
402
  }
403
+ this.stopPolling();
447
404
  this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
448
405
  this.subscriptions.clear();
449
406
  this.queryManager.stopQuery(this.queryId);
@@ -459,7 +416,6 @@ function defaultSubscriptionObserverErrorCallback(error) {
459
416
  function applyNextFetchPolicy(options) {
460
417
  var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
461
418
  if (nextFetchPolicy) {
462
- options.nextFetchPolicy = void 0;
463
419
  options.fetchPolicy = typeof nextFetchPolicy === "function"
464
420
  ? nextFetchPolicy.call(options, fetchPolicy)
465
421
  : nextFetchPolicy;
@@ -529,8 +485,7 @@ var LocalState = (function () {
529
485
  };
530
486
  LocalState.prototype.prepareContext = function (context) {
531
487
  var cache = this.cache;
532
- return tslib.__assign(tslib.__assign({}, context), { cache: cache,
533
- getCacheKey: function (obj) {
488
+ return tslib.__assign(tslib.__assign({}, context), { cache: cache, getCacheKey: function (obj) {
534
489
  return cache.identify(obj);
535
490
  } });
536
491
  };
@@ -594,8 +549,7 @@ var LocalState = (function () {
594
549
  _a = this, cache = _a.cache, client = _a.client;
595
550
  execContext = {
596
551
  fragmentMap: fragmentMap,
597
- context: tslib.__assign(tslib.__assign({}, context), { cache: cache,
598
- client: client }),
552
+ context: tslib.__assign(tslib.__assign({}, context), { cache: cache, client: client }),
599
553
  variables: variables,
600
554
  fragmentMatcher: fragmentMatcher,
601
555
  defaultOperationType: defaultOperationType,
@@ -815,12 +769,13 @@ var QueryInfo = (function () {
815
769
  };
816
770
  QueryInfo.prototype.getDiffOptions = function (variables) {
817
771
  if (variables === void 0) { variables = this.variables; }
772
+ var oq = this.observableQuery;
818
773
  return {
819
774
  query: this.document,
820
775
  variables: variables,
821
776
  returnPartialData: true,
822
777
  optimistic: true,
823
- canonizeResults: this.canonize(),
778
+ canonizeResults: !oq || oq.options.canonizeResults !== false,
824
779
  };
825
780
  };
826
781
  QueryInfo.prototype.setDiff = function (diff) {
@@ -907,10 +862,6 @@ var QueryInfo = (function () {
907
862
  this.cancel = this.cache.watch(this.lastWatch = watchOptions);
908
863
  }
909
864
  };
910
- QueryInfo.prototype.canonize = function () {
911
- var oq = this.observableQuery;
912
- return !oq || oq.options.canonizeResults !== false;
913
- };
914
865
  QueryInfo.prototype.resetLastWrite = function () {
915
866
  this.lastWrite = void 0;
916
867
  };
@@ -928,7 +879,7 @@ var QueryInfo = (function () {
928
879
  if (options.fetchPolicy === 'no-cache') {
929
880
  this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
930
881
  }
931
- else if (!this.stopped && cacheWriteBehavior !== 0) {
882
+ else if (cacheWriteBehavior !== 0) {
932
883
  if (shouldWriteResult(result, options.errorPolicy)) {
933
884
  this.cache.performTransaction(function (cache) {
934
885
  if (_this.shouldWrite(result, options.variables)) {
@@ -1024,7 +975,7 @@ var QueryManager = (function () {
1024
975
  this.queries.forEach(function (_info, queryId) {
1025
976
  _this.stopQueryNoBroadcast(queryId);
1026
977
  });
1027
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(13));
978
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(14));
1028
979
  };
1029
980
  QueryManager.prototype.cancelPendingFetches = function (error) {
1030
981
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -1037,8 +988,8 @@ var QueryManager = (function () {
1037
988
  return tslib.__generator(this, function (_e) {
1038
989
  switch (_e.label) {
1039
990
  case 0:
1040
- __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 14);
1041
- __DEV__ ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.") : tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', 15);
991
+ __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 15);
992
+ __DEV__ ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.") : tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', 16);
1042
993
  mutationId = this.generateMutationId();
1043
994
  mutation = this.transform(mutation).document;
1044
995
  variables = this.getVariables(mutation, variables);
@@ -1323,10 +1274,10 @@ var QueryManager = (function () {
1323
1274
  var _this = this;
1324
1275
  if (queryId === void 0) { queryId = this.generateQueryId(); }
1325
1276
  __DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
1326
- 'in the query option.') : tsInvariant.invariant(options.query, 16);
1327
- __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 17);
1328
- __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 18);
1329
- __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 19);
1277
+ 'in the query option.') : tsInvariant.invariant(options.query, 17);
1278
+ __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 18);
1279
+ __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 19);
1280
+ __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 20);
1330
1281
  return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
1331
1282
  };
1332
1283
  QueryManager.prototype.generateQueryId = function () {
@@ -1348,7 +1299,7 @@ var QueryManager = (function () {
1348
1299
  queryInfo.stop();
1349
1300
  };
1350
1301
  QueryManager.prototype.clearStore = function () {
1351
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(20));
1302
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(21));
1352
1303
  this.queries.forEach(function (queryInfo) {
1353
1304
  if (queryInfo.observableQuery) {
1354
1305
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -1376,9 +1327,12 @@ var QueryManager = (function () {
1376
1327
  var legacyQueryOptions = new Set();
1377
1328
  if (Array.isArray(include)) {
1378
1329
  include.forEach(function (desc) {
1379
- if (typeof desc === "string" || utilities.isDocumentNode(desc)) {
1330
+ if (typeof desc === "string") {
1380
1331
  queryNamesAndDocs.set(desc, false);
1381
1332
  }
1333
+ else if (utilities.isDocumentNode(desc)) {
1334
+ queryNamesAndDocs.set(_this.transform(desc).document, false);
1335
+ }
1382
1336
  else if (utilities.isNonNullObject(desc) && desc.query) {
1383
1337
  legacyQueryOptions.add(desc);
1384
1338
  }
@@ -1715,7 +1669,7 @@ var QueryManager = (function () {
1715
1669
  utilities.isNonEmptyArray(diff.missing) &&
1716
1670
  !equality.equal(data, {}) &&
1717
1671
  !returnPartialData) {
1718
- __DEV__ && tsInvariant.invariant.warn("Missing cache result fields: " + diff.missing.map(function (m) { return m.path.join('.'); }).join(', '), diff.missing);
1672
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + diff.missing.map(function (m) { return m.path.join('.'); }).join(', '), diff.missing);
1719
1673
  }
1720
1674
  var fromData = function (data) { return utilities.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
1721
1675
  if (data && _this.transform(query).hasForcedResolvers) {
@@ -2012,6 +1966,9 @@ var ApolloClient = (function () {
2012
1966
  var result = Promise.all(results);
2013
1967
  result.queries = queries;
2014
1968
  result.results = results;
1969
+ result.catch(function (error) {
1970
+ __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
1971
+ });
2015
1972
  return result;
2016
1973
  };
2017
1974
  ApolloClient.prototype.getObservableQueries = function (include) {
@@ -2042,10 +1999,9 @@ var ApolloClient = (function () {
2042
1999
  return ApolloClient;
2043
2000
  }());
2044
2001
 
2045
- tsInvariant.setVerbosity("log");
2002
+ tsInvariant.setVerbosity(utilities.DEV ? "log" : "silent");
2046
2003
 
2047
2004
  exports.Observable = utilities.Observable;
2048
- exports.__DEV__ = utilities.__DEV__;
2049
2005
  exports.isReference = utilities.isReference;
2050
2006
  exports.makeReference = utilities.makeReference;
2051
2007
  exports.setLogVerbosity = tsInvariant.setVerbosity;