@apollo/client 3.6.3 → 3.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/apollo-client.cjs +74 -14
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs.native.js +2289 -0
  5. package/core/core.cjs +1 -1
  6. package/core/core.cjs.map +1 -1
  7. package/core/core.cjs.native.js +2141 -0
  8. package/errors/errors.cjs.native.js +48 -0
  9. package/invariantErrorCodes.js +1 -1
  10. package/link/batch/batch.cjs.native.js +161 -0
  11. package/link/batch-http/batch-http.cjs.native.js +127 -0
  12. package/link/context/context.cjs.native.js +38 -0
  13. package/link/core/core.cjs.native.js +121 -0
  14. package/link/error/error.cjs.native.js +90 -0
  15. package/link/http/http.cjs.native.js +320 -0
  16. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  17. package/link/retry/retry.cjs.native.js +170 -0
  18. package/link/schema/schema.cjs.native.js +56 -0
  19. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  20. package/link/utils/utils.cjs.native.js +115 -0
  21. package/link/ws/ws.cjs.native.js +28 -0
  22. package/main.cjs.native.js +16 -0
  23. package/package.json +13 -14
  24. package/react/components/components.cjs.native.js +79 -0
  25. package/react/context/context.cjs.native.js +67 -0
  26. package/react/hoc/hoc.cjs.native.js +325 -0
  27. package/react/hooks/hooks.cjs +99 -31
  28. package/react/hooks/hooks.cjs.map +1 -1
  29. package/react/hooks/hooks.cjs.native.js +604 -0
  30. package/react/hooks/useQuery.js +1 -1
  31. package/react/hooks/useQuery.js.map +1 -1
  32. package/react/hooks/useSubscription.d.ts.map +1 -1
  33. package/react/hooks/useSubscription.js +17 -7
  34. package/react/hooks/useSubscription.js.map +1 -1
  35. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  36. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  37. package/react/hooks/useSyncExternalStore.js +48 -0
  38. package/react/hooks/useSyncExternalStore.js.map +1 -0
  39. package/react/parser/parser.cjs.native.js +103 -0
  40. package/react/react.cjs.native.js +22 -0
  41. package/react/ssr/ssr.cjs.native.js +150 -0
  42. package/testing/core/core.cjs.native.js +288 -0
  43. package/testing/testing.cjs.native.js +58 -0
  44. package/utilities/common/canUse.d.ts +2 -0
  45. package/utilities/common/canUse.d.ts.map +1 -1
  46. package/utilities/common/canUse.js +6 -2
  47. package/utilities/common/canUse.js.map +1 -1
  48. package/utilities/globals/globals.cjs.native.js +56 -0
  49. package/utilities/observables/Concast.d.ts.map +1 -1
  50. package/utilities/observables/Concast.js +5 -2
  51. package/utilities/observables/Concast.js.map +1 -1
  52. package/utilities/policies/pagination.d.ts.map +1 -1
  53. package/utilities/policies/pagination.js +9 -7
  54. package/utilities/policies/pagination.js.map +1 -1
  55. package/utilities/utilities.cjs +21 -11
  56. package/utilities/utilities.cjs.map +1 -1
  57. package/utilities/utilities.cjs.native.js +1284 -0
  58. package/version.js +1 -1
@@ -0,0 +1,325 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var globals = require('../../utilities/globals');
6
+ var parser = require('../parser');
7
+ var tslib = require('tslib');
8
+ var React = require('react');
9
+ var hoistNonReactStatics = require('hoist-non-react-statics');
10
+ var components = require('../components');
11
+ var context = require('../context');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ for (var k in e) {
20
+ n[k] = e[k];
21
+ }
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
+ var hoistNonReactStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatics);
29
+
30
+ var defaultMapPropsToOptions = function () { return ({}); };
31
+ var defaultMapPropsToSkip = function () { return false; };
32
+ function getDisplayName$1(WrappedComponent) {
33
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
34
+ }
35
+ function calculateVariablesFromProps(operation, props) {
36
+ var variables = {};
37
+ for (var _i = 0, _a = operation.variables; _i < _a.length; _i++) {
38
+ var _b = _a[_i], variable = _b.variable, type = _b.type;
39
+ if (!variable.name || !variable.name.value)
40
+ continue;
41
+ var variableName = variable.name.value;
42
+ var variableProp = props[variableName];
43
+ if (typeof variableProp !== 'undefined') {
44
+ variables[variableName] = variableProp;
45
+ continue;
46
+ }
47
+ if (type.kind !== 'NonNullType') {
48
+ variables[variableName] = undefined;
49
+ }
50
+ }
51
+ return variables;
52
+ }
53
+ var GraphQLBase = (function (_super) {
54
+ tslib.__extends(GraphQLBase, _super);
55
+ function GraphQLBase(props) {
56
+ var _this = _super.call(this, props) || this;
57
+ _this.withRef = false;
58
+ _this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
59
+ return _this;
60
+ }
61
+ GraphQLBase.prototype.getWrappedInstance = function () {
62
+ __DEV__ ? globals.invariant(this.withRef, "To access the wrapped instance, you need to specify " +
63
+ "{ withRef: true } in the options") : globals.invariant(this.withRef, 27);
64
+ return this.wrappedInstance;
65
+ };
66
+ GraphQLBase.prototype.setWrappedInstance = function (ref) {
67
+ this.wrappedInstance = ref;
68
+ };
69
+ return GraphQLBase;
70
+ }(React__namespace.Component));
71
+
72
+ function withQuery(document, operationOptions) {
73
+ if (operationOptions === void 0) { operationOptions = {}; }
74
+ var operation = parser.parser(document);
75
+ var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c;
76
+ var mapPropsToOptions = options;
77
+ if (typeof mapPropsToOptions !== 'function') {
78
+ mapPropsToOptions = function () { return options; };
79
+ }
80
+ var mapPropsToSkip = skip;
81
+ if (typeof mapPropsToSkip !== 'function') {
82
+ mapPropsToSkip = function () { return skip; };
83
+ }
84
+ var lastResultProps;
85
+ return function (WrappedComponent) {
86
+ var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
87
+ var GraphQL = (function (_super) {
88
+ tslib.__extends(GraphQL, _super);
89
+ function GraphQL() {
90
+ return _super !== null && _super.apply(this, arguments) || this;
91
+ }
92
+ GraphQL.prototype.render = function () {
93
+ var _this = this;
94
+ var props = this.props;
95
+ var shouldSkip = mapPropsToSkip(props);
96
+ var opts = shouldSkip
97
+ ? Object.create(null)
98
+ : tslib.__assign({}, mapPropsToOptions(props));
99
+ if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
100
+ opts.variables = calculateVariablesFromProps(operation, props);
101
+ }
102
+ return (React__namespace.createElement(components.Query, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, query: document }), function (_a) {
103
+ var _b, _c;
104
+ _a.client; var data = _a.data, r = tslib.__rest(_a, ["client", "data"]);
105
+ if (operationOptions.withRef) {
106
+ _this.withRef = true;
107
+ props = Object.assign({}, props, {
108
+ ref: _this.setWrappedInstance
109
+ });
110
+ }
111
+ if (shouldSkip) {
112
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
113
+ }
114
+ var result = Object.assign(r, data || {});
115
+ var name = operationOptions.name || 'data';
116
+ var childProps = (_b = {}, _b[name] = result, _b);
117
+ if (operationOptions.props) {
118
+ var newResult = (_c = {},
119
+ _c[name] = result,
120
+ _c.ownProps = props,
121
+ _c);
122
+ lastResultProps = operationOptions.props(newResult, lastResultProps);
123
+ childProps = lastResultProps;
124
+ }
125
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
126
+ }));
127
+ };
128
+ GraphQL.displayName = graphQLDisplayName;
129
+ GraphQL.WrappedComponent = WrappedComponent;
130
+ return GraphQL;
131
+ }(GraphQLBase));
132
+ return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
133
+ };
134
+ }
135
+
136
+ function withMutation(document, operationOptions) {
137
+ if (operationOptions === void 0) { operationOptions = {}; }
138
+ var operation = parser.parser(document);
139
+ var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.alias, alias = _b === void 0 ? 'Apollo' : _b;
140
+ var mapPropsToOptions = options;
141
+ if (typeof mapPropsToOptions !== 'function')
142
+ mapPropsToOptions = function () { return options; };
143
+ return function (WrappedComponent) {
144
+ var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
145
+ var GraphQL = (function (_super) {
146
+ tslib.__extends(GraphQL, _super);
147
+ function GraphQL() {
148
+ return _super !== null && _super.apply(this, arguments) || this;
149
+ }
150
+ GraphQL.prototype.render = function () {
151
+ var props = this.props;
152
+ var opts = mapPropsToOptions(props);
153
+ if (operationOptions.withRef) {
154
+ this.withRef = true;
155
+ props = Object.assign({}, props, {
156
+ ref: this.setWrappedInstance
157
+ });
158
+ }
159
+ if (!opts.variables && operation.variables.length > 0) {
160
+ opts.variables = calculateVariablesFromProps(operation, props);
161
+ }
162
+ return (React__namespace.createElement(components.Mutation, tslib.__assign({ ignoreResults: true }, opts, { mutation: document }), function (mutate, _a) {
163
+ var _b, _c;
164
+ var data = _a.data, r = tslib.__rest(_a, ["data"]);
165
+ var result = Object.assign(r, data || {});
166
+ var name = operationOptions.name || 'mutate';
167
+ var resultName = operationOptions.name
168
+ ? "".concat(name, "Result")
169
+ : 'result';
170
+ var childProps = (_b = {},
171
+ _b[name] = mutate,
172
+ _b[resultName] = result,
173
+ _b);
174
+ if (operationOptions.props) {
175
+ var newResult = (_c = {},
176
+ _c[name] = mutate,
177
+ _c[resultName] = result,
178
+ _c.ownProps = props,
179
+ _c);
180
+ childProps = operationOptions.props(newResult);
181
+ }
182
+ return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps));
183
+ }));
184
+ };
185
+ GraphQL.displayName = graphQLDisplayName;
186
+ GraphQL.WrappedComponent = WrappedComponent;
187
+ return GraphQL;
188
+ }(GraphQLBase));
189
+ return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
190
+ };
191
+ }
192
+
193
+ function withSubscription(document, operationOptions) {
194
+ if (operationOptions === void 0) { operationOptions = {}; }
195
+ var operation = parser.parser(document);
196
+ var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c, shouldResubscribe = operationOptions.shouldResubscribe;
197
+ var mapPropsToOptions = options;
198
+ if (typeof mapPropsToOptions !== 'function')
199
+ mapPropsToOptions = function () { return options; };
200
+ var mapPropsToSkip = skip;
201
+ if (typeof mapPropsToSkip !== 'function')
202
+ mapPropsToSkip = function () { return skip; };
203
+ var lastResultProps;
204
+ return function (WrappedComponent) {
205
+ var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
206
+ var GraphQL = (function (_super) {
207
+ tslib.__extends(GraphQL, _super);
208
+ function GraphQL(props) {
209
+ var _this = _super.call(this, props) || this;
210
+ _this.state = { resubscribe: false };
211
+ return _this;
212
+ }
213
+ GraphQL.prototype.updateResubscribe = function (resubscribe) {
214
+ this.setState({ resubscribe: resubscribe });
215
+ };
216
+ GraphQL.prototype.componentDidUpdate = function (prevProps) {
217
+ var resubscribe = !!(shouldResubscribe &&
218
+ shouldResubscribe(prevProps, this.props));
219
+ if (this.state.resubscribe !== resubscribe) {
220
+ this.updateResubscribe(resubscribe);
221
+ }
222
+ };
223
+ GraphQL.prototype.render = function () {
224
+ var _this = this;
225
+ var props = this.props;
226
+ var shouldSkip = mapPropsToSkip(props);
227
+ var opts = shouldSkip
228
+ ? Object.create(null)
229
+ : mapPropsToOptions(props);
230
+ if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
231
+ opts.variables = calculateVariablesFromProps(operation, props);
232
+ }
233
+ return (React__namespace.createElement(components.Subscription, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, subscription: document, shouldResubscribe: this.state.resubscribe }), function (_a) {
234
+ var _b, _c;
235
+ var data = _a.data, r = tslib.__rest(_a, ["data"]);
236
+ if (operationOptions.withRef) {
237
+ _this.withRef = true;
238
+ props = Object.assign({}, props, {
239
+ ref: _this.setWrappedInstance
240
+ });
241
+ }
242
+ if (shouldSkip) {
243
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
244
+ }
245
+ var result = Object.assign(r, data || {});
246
+ var name = operationOptions.name || 'data';
247
+ var childProps = (_b = {}, _b[name] = result, _b);
248
+ if (operationOptions.props) {
249
+ var newResult = (_c = {},
250
+ _c[name] = result,
251
+ _c.ownProps = props,
252
+ _c);
253
+ lastResultProps = operationOptions.props(newResult, lastResultProps);
254
+ childProps = lastResultProps;
255
+ }
256
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
257
+ }));
258
+ };
259
+ GraphQL.displayName = graphQLDisplayName;
260
+ GraphQL.WrappedComponent = WrappedComponent;
261
+ return GraphQL;
262
+ }(GraphQLBase));
263
+ return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
264
+ };
265
+ }
266
+
267
+ function graphql(document, operationOptions) {
268
+ if (operationOptions === void 0) { operationOptions = {}; }
269
+ switch (parser.parser(document).type) {
270
+ case parser.DocumentType.Mutation:
271
+ return withMutation(document, operationOptions);
272
+ case parser.DocumentType.Subscription:
273
+ return withSubscription(document, operationOptions);
274
+ case parser.DocumentType.Query:
275
+ default:
276
+ return withQuery(document, operationOptions);
277
+ }
278
+ }
279
+
280
+ function getDisplayName(WrappedComponent) {
281
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
282
+ }
283
+ function withApollo(WrappedComponent, operationOptions) {
284
+ if (operationOptions === void 0) { operationOptions = {}; }
285
+ var withDisplayName = "withApollo(".concat(getDisplayName(WrappedComponent), ")");
286
+ var WithApollo = (function (_super) {
287
+ tslib.__extends(WithApollo, _super);
288
+ function WithApollo(props) {
289
+ var _this = _super.call(this, props) || this;
290
+ _this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
291
+ return _this;
292
+ }
293
+ WithApollo.prototype.getWrappedInstance = function () {
294
+ __DEV__ ? globals.invariant(operationOptions.withRef, "To access the wrapped instance, you need to specify " +
295
+ "{ withRef: true } in the options") : globals.invariant(operationOptions.withRef, 28);
296
+ return this.wrappedInstance;
297
+ };
298
+ WithApollo.prototype.setWrappedInstance = function (ref) {
299
+ this.wrappedInstance = ref;
300
+ };
301
+ WithApollo.prototype.render = function () {
302
+ var _this = this;
303
+ return (React__namespace.createElement(context.ApolloConsumer, null, function (client) {
304
+ var props = Object.assign({}, _this.props, {
305
+ client: client,
306
+ ref: operationOptions.withRef
307
+ ? _this.setWrappedInstance
308
+ : undefined
309
+ });
310
+ return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props));
311
+ }));
312
+ };
313
+ WithApollo.displayName = withDisplayName;
314
+ WithApollo.WrappedComponent = WrappedComponent;
315
+ return WithApollo;
316
+ }(React__namespace.Component));
317
+ return hoistNonReactStatics__default(WithApollo, WrappedComponent, {});
318
+ }
319
+
320
+ exports.graphql = graphql;
321
+ exports.withApollo = withApollo;
322
+ exports.withMutation = withMutation;
323
+ exports.withQuery = withQuery;
324
+ exports.withSubscription = withSubscription;
325
+ //# sourceMappingURL=hoc.cjs.map
@@ -3,18 +3,31 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var globals = require('../../utilities/globals');
6
- var react = require('react');
6
+ var React = require('react');
7
7
  var context = require('../context');
8
8
  var tslib = require('tslib');
9
- var index_js = require('use-sync-external-store/shim/index.js');
9
+ var utilities = require('../../utilities');
10
10
  var equality = require('@wry/equality');
11
11
  var core = require('../../core');
12
12
  var errors = require('../../errors');
13
13
  var parser = require('../parser');
14
- var utilities = require('../../utilities');
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ for (var k in e) {
20
+ n[k] = e[k];
21
+ }
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
15
28
 
16
29
  function useApolloClient(override) {
17
- var context$1 = react.useContext(context.getApolloContext());
30
+ var context$1 = React.useContext(context.getApolloContext());
18
31
  var client = override || context$1.client;
19
32
  __DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
20
33
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
@@ -22,20 +35,65 @@ function useApolloClient(override) {
22
35
  return client;
23
36
  }
24
37
 
38
+ var didWarnUncachedGetSnapshot = false;
39
+ var uSESKey = "useSyncExternalStore";
40
+ var realHook = React__namespace[uSESKey];
41
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
42
+ var value = getSnapshot();
43
+ if (__DEV__ &&
44
+ !didWarnUncachedGetSnapshot &&
45
+ value !== getSnapshot()) {
46
+ didWarnUncachedGetSnapshot = true;
47
+ __DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
48
+ }
49
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
50
+ if (utilities.canUseLayoutEffect) {
51
+ React__namespace.useLayoutEffect(function () {
52
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
53
+ if (checkIfSnapshotChanged(inst)) {
54
+ forceUpdate({ inst: inst });
55
+ }
56
+ }, [subscribe, value, getSnapshot]);
57
+ }
58
+ else {
59
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
60
+ }
61
+ React__namespace.useEffect(function () {
62
+ if (checkIfSnapshotChanged(inst)) {
63
+ forceUpdate({ inst: inst });
64
+ }
65
+ return subscribe(function handleStoreChange() {
66
+ if (checkIfSnapshotChanged(inst)) {
67
+ forceUpdate({ inst: inst });
68
+ }
69
+ });
70
+ }, [subscribe]);
71
+ return value;
72
+ });
73
+ function checkIfSnapshotChanged(_a) {
74
+ var value = _a.value, getSnapshot = _a.getSnapshot;
75
+ try {
76
+ return value !== getSnapshot();
77
+ }
78
+ catch (_b) {
79
+ return true;
80
+ }
81
+ }
82
+
25
83
  var hasOwnProperty = Object.prototype.hasOwnProperty;
26
84
  function useQuery(query, options) {
27
85
  if (options === void 0) { options = Object.create(null); }
28
86
  return useInternalState(useApolloClient(options.client), query).useQuery(options);
29
87
  }
30
88
  function useInternalState(client, query) {
31
- var stateRef = react.useRef();
89
+ var stateRef = React.useRef();
32
90
  if (!stateRef.current ||
33
91
  client !== stateRef.current.client ||
34
92
  query !== stateRef.current.query) {
35
93
  stateRef.current = new InternalState(client, query);
36
94
  }
37
95
  var state = stateRef.current;
38
- var _a = react.useState(0); _a[0]; var setTick = _a[1];
96
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
39
97
  state.forceUpdate = function () {
40
98
  setTick(function (tick) { return tick + 1; });
41
99
  };
@@ -75,10 +133,10 @@ var InternalState = (function () {
75
133
  };
76
134
  InternalState.prototype.useQuery = function (options) {
77
135
  var _this = this;
78
- this.renderPromises = react.useContext(context.getApolloContext()).renderPromises;
136
+ this.renderPromises = React.useContext(context.getApolloContext()).renderPromises;
79
137
  this.useOptions(options);
80
138
  var obsQuery = this.useObservableQuery();
81
- var result = index_js.useSyncExternalStore(react.useCallback(function () {
139
+ var result = useSyncExternalStore(React.useCallback(function () {
82
140
  if (_this.renderPromises) {
83
141
  return function () { };
84
142
  }
@@ -204,7 +262,7 @@ var InternalState = (function () {
204
262
  && this.renderPromises.getSSRObservable(this.watchQueryOptions)
205
263
  || this.observable
206
264
  || this.client.watchQuery(core.mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
207
- this.obsQueryFields = react.useMemo(function () { return ({
265
+ this.obsQueryFields = React.useMemo(function () { return ({
208
266
  refetch: obsQuery.refetch.bind(obsQuery),
209
267
  reobserve: obsQuery.reobserve.bind(obsQuery),
210
268
  fetchMore: obsQuery.fetchMore.bind(obsQuery),
@@ -285,14 +343,14 @@ var EAGER_METHODS = [
285
343
  ];
286
344
  function useLazyQuery(query, options) {
287
345
  var internalState = useInternalState(useApolloClient(options && options.client), query);
288
- var execOptionsRef = react.useRef();
346
+ var execOptionsRef = React.useRef();
289
347
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
290
348
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
291
349
  internalState.getDefaultFetchPolicy();
292
350
  var result = Object.assign(useQueryResult, {
293
351
  called: !!execOptionsRef.current,
294
352
  });
295
- var eagerMethods = react.useMemo(function () {
353
+ var eagerMethods = React.useMemo(function () {
296
354
  var eagerMethods = {};
297
355
  var _loop_1 = function (key) {
298
356
  var method = result[key];
@@ -311,7 +369,7 @@ function useLazyQuery(query, options) {
311
369
  return eagerMethods;
312
370
  }, []);
313
371
  Object.assign(result, eagerMethods);
314
- var execute = react.useCallback(function (executeOptions) {
372
+ var execute = React.useCallback(function (executeOptions) {
315
373
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
316
374
  fetchPolicy: initialFetchPolicy,
317
375
  };
@@ -327,12 +385,12 @@ function useLazyQuery(query, options) {
327
385
  function useMutation(mutation, options) {
328
386
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
329
387
  parser.verifyDocumentType(mutation, parser.DocumentType.Mutation);
330
- var _a = react.useState({
388
+ var _a = React.useState({
331
389
  called: false,
332
390
  loading: false,
333
391
  client: client,
334
392
  }), result = _a[0], setResult = _a[1];
335
- var ref = react.useRef({
393
+ var ref = React.useRef({
336
394
  result: result,
337
395
  mutationId: 0,
338
396
  isMounted: true,
@@ -343,7 +401,7 @@ function useMutation(mutation, options) {
343
401
  {
344
402
  Object.assign(ref.current, { client: client, options: options, mutation: mutation });
345
403
  }
346
- var execute = react.useCallback(function (executeOptions) {
404
+ var execute = React.useCallback(function (executeOptions) {
347
405
  if (executeOptions === void 0) { executeOptions = {}; }
348
406
  var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
349
407
  var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
@@ -403,10 +461,10 @@ function useMutation(mutation, options) {
403
461
  throw error;
404
462
  });
405
463
  }, []);
406
- var reset = react.useCallback(function () {
464
+ var reset = React.useCallback(function () {
407
465
  setResult({ called: false, loading: false, client: client });
408
466
  }, []);
409
- react.useEffect(function () {
467
+ React.useEffect(function () {
410
468
  ref.current.isMounted = true;
411
469
  return function () {
412
470
  ref.current.isMounted = false;
@@ -418,13 +476,13 @@ function useMutation(mutation, options) {
418
476
  function useSubscription(subscription, options) {
419
477
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
420
478
  parser.verifyDocumentType(subscription, parser.DocumentType.Subscription);
421
- var _a = react.useState({
479
+ var _a = React.useState({
422
480
  loading: !(options === null || options === void 0 ? void 0 : options.skip),
423
481
  error: void 0,
424
482
  data: void 0,
425
483
  variables: options === null || options === void 0 ? void 0 : options.variables,
426
484
  }), result = _a[0], setResult = _a[1];
427
- var _b = react.useState(function () {
485
+ var _b = React.useState(function () {
428
486
  if (options === null || options === void 0 ? void 0 : options.skip) {
429
487
  return null;
430
488
  }
@@ -435,15 +493,21 @@ function useSubscription(subscription, options) {
435
493
  context: options === null || options === void 0 ? void 0 : options.context,
436
494
  });
437
495
  }), observable = _b[0], setObservable = _b[1];
438
- var ref = react.useRef({ client: client, subscription: subscription, options: options });
439
- react.useEffect(function () {
496
+ var canResetObservableRef = React.useRef(false);
497
+ React.useEffect(function () {
498
+ return function () {
499
+ canResetObservableRef.current = true;
500
+ };
501
+ }, []);
502
+ var ref = React.useRef({ client: client, subscription: subscription, options: options });
503
+ React.useEffect(function () {
440
504
  var _a, _b, _c, _d;
441
505
  var shouldResubscribe = options === null || options === void 0 ? void 0 : options.shouldResubscribe;
442
506
  if (typeof shouldResubscribe === 'function') {
443
507
  shouldResubscribe = !!shouldResubscribe(options);
444
508
  }
445
509
  if (options === null || options === void 0 ? void 0 : options.skip) {
446
- if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
510
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
447
511
  setResult({
448
512
  loading: false,
449
513
  data: void 0,
@@ -451,13 +515,16 @@ function useSubscription(subscription, options) {
451
515
  variables: options === null || options === void 0 ? void 0 : options.variables,
452
516
  });
453
517
  setObservable(null);
518
+ canResetObservableRef.current = false;
454
519
  }
455
520
  }
456
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
457
- subscription !== ref.current.subscription ||
458
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
459
- !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
460
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
521
+ else if ((shouldResubscribe !== false &&
522
+ (client !== ref.current.client ||
523
+ subscription !== ref.current.subscription ||
524
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
525
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
526
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
527
+ canResetObservableRef.current) {
461
528
  setResult({
462
529
  loading: true,
463
530
  data: void 0,
@@ -470,10 +537,11 @@ function useSubscription(subscription, options) {
470
537
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
471
538
  context: options === null || options === void 0 ? void 0 : options.context,
472
539
  }));
540
+ canResetObservableRef.current = false;
473
541
  }
474
542
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
475
- }, [client, subscription, options]);
476
- react.useEffect(function () {
543
+ }, [client, subscription, options, canResetObservableRef.current]);
544
+ React.useEffect(function () {
477
545
  if (!observable) {
478
546
  return;
479
547
  }
@@ -514,8 +582,8 @@ function useSubscription(subscription, options) {
514
582
 
515
583
  function useReactiveVar(rv) {
516
584
  var value = rv();
517
- var setValue = react.useState(value)[1];
518
- react.useEffect(function () {
585
+ var setValue = React.useState(value)[1];
586
+ React.useEffect(function () {
519
587
  var probablySameValue = rv();
520
588
  if (value !== probablySameValue) {
521
589
  setValue(probablySameValue);