@apollo/client 3.5.10 → 3.6.0-beta.10

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 (61) hide show
  1. package/apollo-client.cjs +387 -286
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/core/ApolloClient.d.ts.map +1 -1
  5. package/core/ApolloClient.js +2 -2
  6. package/core/ApolloClient.js.map +1 -1
  7. package/core/ObservableQuery.d.ts +8 -2
  8. package/core/ObservableQuery.d.ts.map +1 -1
  9. package/core/ObservableQuery.js +75 -32
  10. package/core/ObservableQuery.js.map +1 -1
  11. package/core/QueryInfo.d.ts.map +1 -1
  12. package/core/QueryInfo.js +4 -2
  13. package/core/QueryInfo.js.map +1 -1
  14. package/core/QueryManager.d.ts +5 -2
  15. package/core/QueryManager.d.ts.map +1 -1
  16. package/core/QueryManager.js +18 -11
  17. package/core/QueryManager.js.map +1 -1
  18. package/core/core.cjs +98 -48
  19. package/core/core.cjs.map +1 -1
  20. package/core/index.d.ts +1 -1
  21. package/core/index.d.ts.map +1 -1
  22. package/core/index.js +1 -1
  23. package/core/index.js.map +1 -1
  24. package/core/watchQueryOptions.d.ts +8 -1
  25. package/core/watchQueryOptions.d.ts.map +1 -1
  26. package/core/watchQueryOptions.js.map +1 -1
  27. package/invariantErrorCodes.js +1 -1
  28. package/link/batch/batch.cjs +47 -37
  29. package/link/batch/batch.cjs.map +1 -1
  30. package/link/batch/batching.d.ts +2 -6
  31. package/link/batch/batching.d.ts.map +1 -1
  32. package/link/batch/batching.js +47 -37
  33. package/link/batch/batching.js.map +1 -1
  34. package/package.json +17 -16
  35. package/react/hooks/hooks.cjs +262 -209
  36. package/react/hooks/hooks.cjs.map +1 -1
  37. package/react/hooks/options.d.ts +3 -0
  38. package/react/hooks/options.d.ts.map +1 -0
  39. package/react/hooks/options.js +20 -0
  40. package/react/hooks/options.js.map +1 -0
  41. package/react/hooks/useLazyQuery.d.ts +2 -2
  42. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  43. package/react/hooks/useLazyQuery.js +3 -1
  44. package/react/hooks/useLazyQuery.js.map +1 -1
  45. package/react/hooks/useMutation.js.map +1 -1
  46. package/react/hooks/useQuery.d.ts +2 -2
  47. package/react/hooks/useQuery.d.ts.map +1 -1
  48. package/react/hooks/useQuery.js +237 -205
  49. package/react/hooks/useQuery.js.map +1 -1
  50. package/react/ssr/RenderPromises.d.ts +1 -1
  51. package/react/ssr/RenderPromises.d.ts.map +1 -1
  52. package/react/ssr/RenderPromises.js +2 -2
  53. package/react/ssr/RenderPromises.js.map +1 -1
  54. package/react/ssr/ssr.cjs +2 -2
  55. package/react/ssr/ssr.cjs.map +1 -1
  56. package/react/types/types.d.ts +3 -0
  57. package/react/types/types.d.ts.map +1 -1
  58. package/react/types/types.js.map +1 -1
  59. package/testing/core/mocking/mockFetch.js +1 -1
  60. package/testing/core/mocking/mockFetch.js.map +1 -1
  61. package/version.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "3.5.10",
3
+ "version": "3.6.0-beta.10",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -55,32 +55,33 @@
55
55
  "optimism": "^0.16.1",
56
56
  "prop-types": "^15.7.2",
57
57
  "symbol-observable": "^4.0.0",
58
- "ts-invariant": "^0.9.4",
58
+ "ts-invariant": "^0.10.0",
59
59
  "tslib": "^2.3.0",
60
60
  "zen-observable-ts": "^1.2.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@babel/parser": "7.17.3",
64
- "@graphql-tools/schema": "8.3.1",
63
+ "@babel/parser": "7.17.8",
64
+ "@graphql-tools/schema": "8.3.5",
65
65
  "@rollup/plugin-node-resolve": "11.2.1",
66
- "@testing-library/react": "12.1.3",
66
+ "@testing-library/react": "12.1.4",
67
67
  "@testing-library/react-hooks": "7.0.2",
68
68
  "@types/fast-json-stable-stringify": "2.0.0",
69
69
  "@types/fetch-mock": "7.3.5",
70
70
  "@types/glob": "7.2.0",
71
71
  "@types/hoist-non-react-statics": "3.3.1",
72
- "@types/jest": "27.4.0",
73
- "@types/lodash": "4.14.178",
74
- "@types/node": "16.11.25",
75
- "@types/react": "17.0.34",
76
- "@types/react-dom": "17.0.2",
72
+ "@types/jest": "27.4.1",
73
+ "@types/lodash": "4.14.180",
74
+ "@types/node": "16.11.26",
75
+ "@types/react": "17.0.43",
76
+ "@types/react-dom": "17.0.14",
77
+ "acorn": "8.6.0",
77
78
  "bundlesize": "0.18.1",
78
79
  "cross-fetch": "3.1.5",
79
80
  "crypto-hash": "1.3.0",
80
81
  "fetch-mock": "9.11.0",
81
82
  "glob": "7.2.0",
82
83
  "graphql": "16.0.1",
83
- "graphql-ws": "5.6.2",
84
+ "graphql-ws": "5.6.4",
84
85
  "jest": "27.5.1",
85
86
  "jest-fetch-mock": "3.0.3",
86
87
  "jest-junit": "13.0.0",
@@ -90,14 +91,14 @@
90
91
  "recast": "0.21.0",
91
92
  "resolve": "1.22.0",
92
93
  "rimraf": "3.0.2",
93
- "rollup": "2.67.3",
94
+ "rollup": "2.70.1",
94
95
  "rollup-plugin-terser": "7.0.2",
95
96
  "rxjs": "6.6.7",
96
97
  "subscriptions-transport-ws": "0.11.0",
97
- "terser": "5.10.0",
98
- "ts-jest": "27.1.3",
99
- "ts-node": "10.5.0",
100
- "typescript": "4.5.5",
98
+ "terser": "5.12.1",
99
+ "ts-jest": "27.1.4",
100
+ "ts-node": "10.7.0",
101
+ "typescript": "4.6.3",
101
102
  "wait-for-observables": "1.0.3",
102
103
  "whatwg-fetch": "3.6.2"
103
104
  },
@@ -6,10 +6,15 @@ var globals = require('../../utilities/globals');
6
6
  var react = require('react');
7
7
  var context = require('../context');
8
8
  var tslib = require('tslib');
9
- var equality = require('@wry/equality');
10
- var core = require('../../core');
9
+ var equal = require('@wry/equality');
11
10
  var errors = require('../../errors');
11
+ var core = require('../../core');
12
12
  var parser = require('../parser');
13
+ var utilities = require('../../utilities');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
16
+
17
+ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
13
18
 
14
19
  function useApolloClient(override) {
15
20
  var context$1 = react.useContext(context.getApolloContext());
@@ -20,227 +25,274 @@ function useApolloClient(override) {
20
25
  return client;
21
26
  }
22
27
 
23
- function useQuery(query, options) {
24
- var _a;
25
- var context$1 = react.useContext(context.getApolloContext());
26
- var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
27
- var defaultWatchQueryOptions = client.defaultOptions.watchQuery;
28
- parser.verifyDocumentType(query, parser.DocumentType.Query);
29
- var _b = react.useState(function () {
30
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
31
- var obsQuery = null;
32
- if (context$1.renderPromises) {
33
- obsQuery = context$1.renderPromises.getSSRObservable(watchQueryOptions);
28
+ function useNormalizedOptions(optionsOrFunction) {
29
+ var optionsRef = react.useRef();
30
+ var options = optionsRef.current || Object.create(null);
31
+ if (typeof optionsOrFunction === "function") {
32
+ var newOptions = optionsOrFunction(options);
33
+ if (newOptions !== options) {
34
+ Object.assign(options, newOptions, newOptions.variables && {
35
+ variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
36
+ });
34
37
  }
35
- if (!obsQuery) {
36
- obsQuery = client.watchQuery(watchQueryOptions);
37
- if (context$1.renderPromises) {
38
- context$1.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
39
- }
38
+ }
39
+ else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
40
+ options = optionsOrFunction;
41
+ }
42
+ return optionsRef.current = options;
43
+ }
44
+
45
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
46
+ function useQuery(query, optionsOrFunction) {
47
+ var options = useNormalizedOptions(optionsOrFunction);
48
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
49
+ }
50
+ function useInternalState(client, query) {
51
+ var stateRef = react.useRef();
52
+ if (!stateRef.current ||
53
+ client !== stateRef.current.client ||
54
+ query !== stateRef.current.query) {
55
+ stateRef.current = new InternalState(client, query);
56
+ }
57
+ var state = stateRef.current;
58
+ var _a = react.useState(0); _a[0]; var setTick = _a[1];
59
+ state.forceUpdate = function () {
60
+ setTick(function (tick) { return tick + 1; });
61
+ };
62
+ return state;
63
+ }
64
+ var InternalState = (function () {
65
+ function InternalState(client, query) {
66
+ this.client = client;
67
+ this.query = query;
68
+ this.toQueryResultCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
69
+ parser.verifyDocumentType(query, parser.DocumentType.Query);
70
+ }
71
+ InternalState.prototype.forceUpdate = function () {
72
+ };
73
+ InternalState.prototype.useQuery = function (options) {
74
+ this.useOptions(options);
75
+ var obsQuery = this.useObservableQuery();
76
+ this.useSubscriptionEffect(obsQuery);
77
+ var result = this.getCurrentResult();
78
+ this.unsafeHandlePartialRefetch(result);
79
+ return this.toQueryResult(result);
80
+ };
81
+ InternalState.prototype.useOptions = function (options) {
82
+ this.renderPromises = react.useContext(context.getApolloContext()).renderPromises;
83
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
84
+ if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
85
+ this.watchQueryOptions = watchQueryOptions;
86
+ }
87
+ this.ssrDisabled = !!(options && (options.ssr === false ||
88
+ options.skip));
89
+ this.onCompleted = options
90
+ && options.onCompleted
91
+ || InternalState.prototype.onCompleted;
92
+ this.onError = options
93
+ && options.onError
94
+ || InternalState.prototype.onError;
95
+ };
96
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
97
+ var _b;
98
+ if (_a === void 0) { _a = {}; }
99
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
100
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
101
+ if (skip) {
102
+ watchQueryOptions.fetchPolicy = 'standby';
40
103
  }
41
- if (context$1.renderPromises &&
42
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
43
- !(options === null || options === void 0 ? void 0 : options.skip) &&
44
- obsQuery.getCurrentResult().loading) {
45
- context$1.renderPromises.addQueryPromise({
46
- getOptions: function () { return createWatchQueryOptions(query, options, defaultWatchQueryOptions); },
47
- fetchData: function () { return new Promise(function (resolve) {
48
- var sub = obsQuery.subscribe({
49
- next: function (result) {
50
- if (!result.loading) {
104
+ else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
105
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
106
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
107
+ watchQueryOptions.fetchPolicy = 'cache-first';
108
+ }
109
+ else if (!watchQueryOptions.fetchPolicy) {
110
+ var defaultOptions = this.client.defaultOptions.watchQuery;
111
+ watchQueryOptions.fetchPolicy =
112
+ defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
113
+ }
114
+ if (!watchQueryOptions.variables) {
115
+ watchQueryOptions.variables = {};
116
+ }
117
+ return watchQueryOptions;
118
+ };
119
+ InternalState.prototype.onCompleted = function (data) { };
120
+ InternalState.prototype.onError = function (error) { };
121
+ InternalState.prototype.useObservableQuery = function () {
122
+ var _this = this;
123
+ var obsQuery = this.observable =
124
+ this.renderPromises
125
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
126
+ || this.observable
127
+ || this.client.watchQuery(this.watchQueryOptions);
128
+ this.obsQueryFields = react.useMemo(function () { return ({
129
+ refetch: obsQuery.refetch.bind(obsQuery),
130
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
131
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
132
+ startPolling: obsQuery.startPolling.bind(obsQuery),
133
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
134
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
135
+ }); }, [obsQuery]);
136
+ if (this.renderPromises) {
137
+ this.renderPromises.registerSSRObservable(obsQuery);
138
+ if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
139
+ this.renderPromises.addQueryPromise({
140
+ getOptions: function () { return obsQuery.options; },
141
+ fetchData: function () { return new Promise(function (resolve) {
142
+ var sub = obsQuery.subscribe({
143
+ next: function (result) {
144
+ if (!result.loading) {
145
+ resolve();
146
+ sub.unsubscribe();
147
+ }
148
+ },
149
+ error: function () {
51
150
  resolve();
52
151
  sub.unsubscribe();
53
- }
54
- },
55
- error: function () {
56
- resolve();
57
- sub.unsubscribe();
58
- },
59
- complete: function () {
60
- resolve();
61
- },
62
- });
63
- }); },
64
- }, function () { return null; });
152
+ },
153
+ complete: function () {
154
+ resolve();
155
+ },
156
+ });
157
+ }); },
158
+ }, function () { return null; });
159
+ obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
160
+ }
65
161
  }
162
+ var prevOptionsRef = react.useRef({
163
+ watchQueryOptions: this.watchQueryOptions,
164
+ });
165
+ react.useEffect(function () {
166
+ if (_this.renderPromises) ;
167
+ else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
168
+ obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
169
+ prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
170
+ _this.setResult(obsQuery.getCurrentResult());
171
+ }
172
+ }, [obsQuery, this.watchQueryOptions]);
66
173
  return obsQuery;
67
- }), obsQuery = _b[0], setObsQuery = _b[1];
68
- var _c = react.useState(function () {
69
- var _a, _b;
70
- var result = obsQuery.getCurrentResult();
71
- if (!result.loading && options) {
174
+ };
175
+ InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
176
+ var _this = this;
177
+ react.useEffect(function () {
178
+ if (_this.renderPromises) {
179
+ return;
180
+ }
181
+ var onNext = function () {
182
+ var previousResult = _this.result;
183
+ var result = obsQuery.getCurrentResult();
184
+ if (previousResult &&
185
+ previousResult.loading === result.loading &&
186
+ previousResult.networkStatus === result.networkStatus &&
187
+ equal.equal(previousResult.data, result.data)) {
188
+ return;
189
+ }
190
+ _this.setResult(result);
191
+ };
192
+ var onError = function (error) {
193
+ var last = obsQuery["last"];
194
+ subscription.unsubscribe();
195
+ try {
196
+ obsQuery.resetLastResults();
197
+ subscription = obsQuery.subscribe(onNext, onError);
198
+ }
199
+ finally {
200
+ obsQuery["last"] = last;
201
+ }
202
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
203
+ throw error;
204
+ }
205
+ var previousResult = _this.result;
206
+ if (!previousResult ||
207
+ (previousResult && previousResult.loading) ||
208
+ !equal.equal(error, previousResult.error)) {
209
+ _this.setResult({
210
+ data: (previousResult && previousResult.data),
211
+ error: error,
212
+ loading: false,
213
+ networkStatus: core.NetworkStatus.error,
214
+ });
215
+ }
216
+ };
217
+ var subscription = obsQuery.subscribe(onNext, onError);
218
+ return function () { return subscription.unsubscribe(); };
219
+ }, [
220
+ obsQuery,
221
+ this.renderPromises,
222
+ this.client.disableNetworkFetches,
223
+ ]);
224
+ };
225
+ InternalState.prototype.setResult = function (nextResult) {
226
+ var previousResult = this.result;
227
+ if (previousResult && previousResult.data) {
228
+ this.previousData = previousResult.data;
229
+ }
230
+ this.result = nextResult;
231
+ this.forceUpdate();
232
+ this.handleErrorOrCompleted(nextResult);
233
+ };
234
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
235
+ if (!result.loading) {
72
236
  if (result.error) {
73
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
237
+ this.onError(result.error);
74
238
  }
75
239
  else if (result.data) {
76
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
240
+ this.onCompleted(result.data);
77
241
  }
78
242
  }
79
- return result;
80
- }), result = _c[0], setResult = _c[1];
81
- var ref = react.useRef({
82
- client: client,
83
- query: query,
84
- options: options,
85
- result: result,
86
- previousData: void 0,
87
- watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),
88
- });
89
- react.useEffect(function () {
90
- var _a, _b;
91
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
92
- var nextResult;
93
- if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
94
- var obsQuery_1 = client.watchQuery(watchQueryOptions);
95
- setObsQuery(obsQuery_1);
96
- nextResult = obsQuery_1.getCurrentResult();
243
+ };
244
+ InternalState.prototype.getCurrentResult = function () {
245
+ var result = this.result;
246
+ if (!result) {
247
+ result = this.result = this.observable.getCurrentResult();
248
+ this.handleErrorOrCompleted(result);
97
249
  }
98
- else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
99
- obsQuery.setOptions(watchQueryOptions).catch(function () { });
100
- nextResult = obsQuery.getCurrentResult();
101
- ref.current.watchQueryOptions = watchQueryOptions;
102
- }
103
- if (nextResult) {
104
- var previousResult = ref.current.result;
105
- if (previousResult.data) {
106
- ref.current.previousData = previousResult.data;
107
- }
108
- setResult(ref.current.result = nextResult);
109
- if (!nextResult.loading && options) {
110
- if (nextResult.error) {
111
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, nextResult.error);
112
- }
113
- else if (nextResult.data) {
114
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, nextResult.data);
115
- }
116
- }
117
- }
118
- Object.assign(ref.current, { client: client, query: query });
119
- }, [obsQuery, client, query, options]);
120
- react.useEffect(function () {
121
- if (context$1.renderPromises) {
122
- return;
250
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
251
+ this.queryHookOptions.ssr === false) {
252
+ result = {
253
+ loading: true,
254
+ data: void 0,
255
+ error: void 0,
256
+ networkStatus: core.NetworkStatus.loading,
257
+ };
123
258
  }
124
- var subscription = obsQuery.subscribe(onNext, onError);
125
- function onNext() {
126
- var _a, _b;
127
- var previousResult = ref.current.result;
128
- var result = obsQuery.getCurrentResult();
129
- if (previousResult &&
130
- previousResult.loading === result.loading &&
131
- previousResult.networkStatus === result.networkStatus &&
132
- equality.equal(previousResult.data, result.data)) {
133
- return;
134
- }
135
- if (previousResult.data) {
136
- ref.current.previousData = previousResult.data;
137
- }
138
- setResult(ref.current.result = result);
139
- if (!result.loading) {
140
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
141
- }
259
+ else if (this.queryHookOptions.skip ||
260
+ this.queryHookOptions.fetchPolicy === 'standby') {
261
+ result = {
262
+ loading: false,
263
+ data: void 0,
264
+ error: void 0,
265
+ networkStatus: core.NetworkStatus.ready,
266
+ };
142
267
  }
143
- function onError(error) {
144
- var _a, _b;
145
- var last = obsQuery["last"];
146
- subscription.unsubscribe();
147
- try {
148
- obsQuery.resetLastResults();
149
- subscription = obsQuery.subscribe(onNext, onError);
150
- }
151
- finally {
152
- obsQuery["last"] = last;
153
- }
154
- if (!error.hasOwnProperty('graphQLErrors')) {
155
- throw error;
156
- }
157
- var previousResult = ref.current.result;
158
- if ((previousResult && previousResult.loading) ||
159
- !equality.equal(error, previousResult.error)) {
160
- setResult(ref.current.result = {
161
- data: previousResult.data,
162
- error: error,
163
- loading: false,
164
- networkStatus: core.NetworkStatus.error,
165
- });
166
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
167
- }
268
+ return result;
269
+ };
270
+ InternalState.prototype.toQueryResult = function (result) {
271
+ var queryResult = this.toQueryResultCache.get(result);
272
+ if (queryResult)
273
+ return queryResult;
274
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
275
+ this.toQueryResultCache.set(result, queryResult = tslib.__assign(tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: true, previousData: this.previousData }));
276
+ if (!queryResult.error && utilities.isNonEmptyArray(result.errors)) {
277
+ queryResult.error = new errors.ApolloError({ graphQLErrors: result.errors });
168
278
  }
169
- return function () { return subscription.unsubscribe(); };
170
- }, [obsQuery, context$1.renderPromises, client.disableNetworkFetches]);
171
- var partial;
172
- (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
173
- {
174
- if (partial &&
175
- (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
279
+ return queryResult;
280
+ };
281
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
282
+ if (result.partial &&
283
+ this.queryHookOptions.partialRefetch &&
176
284
  !result.loading &&
177
285
  (!result.data || Object.keys(result.data).length === 0) &&
178
- obsQuery.options.fetchPolicy !== 'cache-only') {
179
- result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: core.NetworkStatus.refetch });
180
- obsQuery.refetch();
181
- }
182
- if (context$1.renderPromises &&
183
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
184
- !(options === null || options === void 0 ? void 0 : options.skip) &&
185
- result.loading) {
186
- obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(function () { });
286
+ this.observable.options.fetchPolicy !== 'cache-only') {
287
+ Object.assign(result, {
288
+ loading: true,
289
+ networkStatus: core.NetworkStatus.refetch,
290
+ });
291
+ this.observable.refetch();
187
292
  }
188
- Object.assign(ref.current, { options: options });
189
- }
190
- if ((context$1.renderPromises || client.disableNetworkFetches) &&
191
- (options === null || options === void 0 ? void 0 : options.ssr) === false) {
192
- result = ref.current.result = {
193
- loading: true,
194
- data: void 0,
195
- error: void 0,
196
- networkStatus: core.NetworkStatus.loading,
197
- };
198
- }
199
- else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
200
- result = {
201
- loading: false,
202
- data: void 0,
203
- error: void 0,
204
- networkStatus: core.NetworkStatus.ready,
205
- };
206
- }
207
- if (result.errors && result.errors.length) {
208
- result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new errors.ApolloError({ graphQLErrors: result.errors }) });
209
- }
210
- var obsQueryFields = react.useMemo(function () { return ({
211
- refetch: obsQuery.refetch.bind(obsQuery),
212
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
213
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
214
- startPolling: obsQuery.startPolling.bind(obsQuery),
215
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
216
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
217
- }); }, [obsQuery]);
218
- return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables, client: client, called: true, previousData: ref.current.previousData }), result);
219
- }
220
- function createWatchQueryOptions(query, options, defaultOptions) {
221
- var _a;
222
- if (options === void 0) { options = {}; }
223
- var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var otherOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
224
- var watchQueryOptions = tslib.__assign({ query: query }, otherOptions);
225
- if (defaultOptions) {
226
- watchQueryOptions = core.mergeOptions(defaultOptions, watchQueryOptions);
227
- }
228
- if (skip) {
229
- watchQueryOptions.fetchPolicy = 'standby';
230
- }
231
- else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
232
- (watchQueryOptions.fetchPolicy === 'network-only' ||
233
- watchQueryOptions.fetchPolicy === 'cache-and-network')) {
234
- watchQueryOptions.fetchPolicy = 'cache-first';
235
- }
236
- else if (!watchQueryOptions.fetchPolicy) {
237
- watchQueryOptions.fetchPolicy = 'cache-first';
238
- }
239
- if (!watchQueryOptions.variables) {
240
- watchQueryOptions.variables = {};
241
- }
242
- return watchQueryOptions;
243
- }
293
+ };
294
+ return InternalState;
295
+ }());
244
296
 
245
297
  var EAGER_METHODS = [
246
298
  'refetch',
@@ -249,7 +301,8 @@ var EAGER_METHODS = [
249
301
  'startPolling',
250
302
  'subscribeToMore',
251
303
  ];
252
- function useLazyQuery(query, options) {
304
+ function useLazyQuery(query, optionsOrFunction) {
305
+ var options = useNormalizedOptions(optionsOrFunction);
253
306
  var _a = react.useState({
254
307
  called: false,
255
308
  }), execution = _a[0], setExecution = _a[1];
@@ -340,7 +393,7 @@ function useMutation(mutation, options) {
340
393
  error: error,
341
394
  client: client,
342
395
  };
343
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
396
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
344
397
  setResult(ref.current.result = result_1);
345
398
  }
346
399
  }
@@ -358,7 +411,7 @@ function useMutation(mutation, options) {
358
411
  called: true,
359
412
  client: client,
360
413
  };
361
- if (!equality.equal(ref.current.result, result_2)) {
414
+ if (!equal.equal(ref.current.result, result_2)) {
362
415
  setResult(ref.current.result = result_2);
363
416
  }
364
417
  }
@@ -421,7 +474,7 @@ function useSubscription(subscription, options) {
421
474
  subscription !== ref.current.subscription ||
422
475
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
423
476
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
424
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
477
+ !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
425
478
  setResult({
426
479
  loading: true,
427
480
  data: void 0,