@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.
- package/apollo-client.cjs +387 -286
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +2 -2
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +8 -2
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +75 -32
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +4 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +5 -2
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +18 -11
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +98 -48
- package/core/core.cjs.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/watchQueryOptions.d.ts +8 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batch.cjs +47 -37
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batching.d.ts +2 -6
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js +47 -37
- package/link/batch/batching.js.map +1 -1
- package/package.json +17 -16
- package/react/hooks/hooks.cjs +262 -209
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/options.d.ts +3 -0
- package/react/hooks/options.d.ts.map +1 -0
- package/react/hooks/options.js +20 -0
- package/react/hooks/options.js.map +1 -0
- package/react/hooks/useLazyQuery.d.ts +2 -2
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +3 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +2 -2
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +237 -205
- package/react/hooks/useQuery.js.map +1 -1
- package/react/ssr/RenderPromises.d.ts +1 -1
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js +2 -2
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/ssr.cjs +2 -2
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/types/types.d.ts +3 -0
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/mocking/mockFetch.js +1 -1
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/version.js +1 -1
package/react/hooks/useQuery.js
CHANGED
|
@@ -1,231 +1,263 @@
|
|
|
1
1
|
import { __assign, __rest } from "tslib";
|
|
2
|
-
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
3
3
|
import { equal } from '@wry/equality';
|
|
4
|
-
import { mergeOptions } from "../../core/index.js";
|
|
5
4
|
import { getApolloContext } from "../context/index.js";
|
|
6
5
|
import { ApolloError } from "../../errors/index.js";
|
|
7
6
|
import { NetworkStatus, } from "../../core/index.js";
|
|
8
7
|
import { DocumentType, verifyDocumentType } from "../parser/index.js";
|
|
9
8
|
import { useApolloClient } from "./useApolloClient.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
import { canUseWeakMap, isNonEmptyArray } from "../../utilities/index.js";
|
|
10
|
+
import { useNormalizedOptions } from "./options.js";
|
|
11
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
12
|
+
export function useQuery(query, optionsOrFunction) {
|
|
13
|
+
var options = useNormalizedOptions(optionsOrFunction);
|
|
14
|
+
return useInternalState(useApolloClient(options.client), query).useQuery(options);
|
|
15
|
+
}
|
|
16
|
+
function useInternalState(client, query) {
|
|
17
|
+
var stateRef = useRef();
|
|
18
|
+
if (!stateRef.current ||
|
|
19
|
+
client !== stateRef.current.client ||
|
|
20
|
+
query !== stateRef.current.query) {
|
|
21
|
+
stateRef.current = new InternalState(client, query);
|
|
22
|
+
}
|
|
23
|
+
var state = stateRef.current;
|
|
24
|
+
var _a = useState(0), _tick = _a[0], setTick = _a[1];
|
|
25
|
+
state.forceUpdate = function () {
|
|
26
|
+
setTick(function (tick) { return tick + 1; });
|
|
27
|
+
};
|
|
28
|
+
return state;
|
|
29
|
+
}
|
|
30
|
+
var InternalState = (function () {
|
|
31
|
+
function InternalState(client, query) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
this.query = query;
|
|
34
|
+
this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
|
|
35
|
+
verifyDocumentType(query, DocumentType.Query);
|
|
36
|
+
}
|
|
37
|
+
InternalState.prototype.forceUpdate = function () {
|
|
38
|
+
};
|
|
39
|
+
InternalState.prototype.useQuery = function (options) {
|
|
40
|
+
this.useOptions(options);
|
|
41
|
+
var obsQuery = this.useObservableQuery();
|
|
42
|
+
this.useSubscriptionEffect(obsQuery);
|
|
43
|
+
var result = this.getCurrentResult();
|
|
44
|
+
this.unsafeHandlePartialRefetch(result);
|
|
45
|
+
return this.toQueryResult(result);
|
|
46
|
+
};
|
|
47
|
+
InternalState.prototype.useOptions = function (options) {
|
|
48
|
+
this.renderPromises = useContext(getApolloContext()).renderPromises;
|
|
49
|
+
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
50
|
+
if (!equal(watchQueryOptions, this.watchQueryOptions)) {
|
|
51
|
+
this.watchQueryOptions = watchQueryOptions;
|
|
21
52
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
53
|
+
this.ssrDisabled = !!(options && (options.ssr === false ||
|
|
54
|
+
options.skip));
|
|
55
|
+
this.onCompleted = options
|
|
56
|
+
&& options.onCompleted
|
|
57
|
+
|| InternalState.prototype.onCompleted;
|
|
58
|
+
this.onError = options
|
|
59
|
+
&& options.onError
|
|
60
|
+
|| InternalState.prototype.onError;
|
|
61
|
+
};
|
|
62
|
+
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
63
|
+
var _b;
|
|
64
|
+
if (_a === void 0) { _a = {}; }
|
|
65
|
+
var skip = _a.skip, ssr = _a.ssr, onCompleted = _a.onCompleted, onError = _a.onError, displayName = _a.displayName, otherOptions = __rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
|
|
66
|
+
var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
|
|
67
|
+
if (skip) {
|
|
68
|
+
watchQueryOptions.fetchPolicy = 'standby';
|
|
69
|
+
}
|
|
70
|
+
else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
|
|
71
|
+
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
72
|
+
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
73
|
+
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
74
|
+
}
|
|
75
|
+
else if (!watchQueryOptions.fetchPolicy) {
|
|
76
|
+
var defaultOptions = this.client.defaultOptions.watchQuery;
|
|
77
|
+
watchQueryOptions.fetchPolicy =
|
|
78
|
+
defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
|
|
27
79
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
80
|
+
if (!watchQueryOptions.variables) {
|
|
81
|
+
watchQueryOptions.variables = {};
|
|
82
|
+
}
|
|
83
|
+
return watchQueryOptions;
|
|
84
|
+
};
|
|
85
|
+
InternalState.prototype.onCompleted = function (data) { };
|
|
86
|
+
InternalState.prototype.onError = function (error) { };
|
|
87
|
+
InternalState.prototype.useObservableQuery = function () {
|
|
88
|
+
var _this = this;
|
|
89
|
+
var obsQuery = this.observable =
|
|
90
|
+
this.renderPromises
|
|
91
|
+
&& this.renderPromises.getSSRObservable(this.watchQueryOptions)
|
|
92
|
+
|| this.observable
|
|
93
|
+
|| this.client.watchQuery(this.watchQueryOptions);
|
|
94
|
+
this.obsQueryFields = useMemo(function () { return ({
|
|
95
|
+
refetch: obsQuery.refetch.bind(obsQuery),
|
|
96
|
+
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
97
|
+
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
98
|
+
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
99
|
+
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
100
|
+
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
101
|
+
}); }, [obsQuery]);
|
|
102
|
+
if (this.renderPromises) {
|
|
103
|
+
this.renderPromises.registerSSRObservable(obsQuery);
|
|
104
|
+
if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
|
|
105
|
+
this.renderPromises.addQueryPromise({
|
|
106
|
+
getOptions: function () { return obsQuery.options; },
|
|
107
|
+
fetchData: function () { return new Promise(function (resolve) {
|
|
108
|
+
var sub = obsQuery.subscribe({
|
|
109
|
+
next: function (result) {
|
|
110
|
+
if (!result.loading) {
|
|
111
|
+
resolve();
|
|
112
|
+
sub.unsubscribe();
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
error: function () {
|
|
38
116
|
resolve();
|
|
39
117
|
sub.unsubscribe();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}); },
|
|
51
|
-
}, function () { return null; });
|
|
118
|
+
},
|
|
119
|
+
complete: function () {
|
|
120
|
+
resolve();
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}); },
|
|
124
|
+
}, function () { return null; });
|
|
125
|
+
obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
|
|
126
|
+
}
|
|
52
127
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (!result.loading && options) {
|
|
59
|
-
if (result.error) {
|
|
60
|
-
(_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
|
|
128
|
+
var prevOptionsRef = useRef({
|
|
129
|
+
watchQueryOptions: this.watchQueryOptions,
|
|
130
|
+
});
|
|
131
|
+
useEffect(function () {
|
|
132
|
+
if (_this.renderPromises) {
|
|
61
133
|
}
|
|
62
|
-
else if (
|
|
63
|
-
(
|
|
134
|
+
else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
|
|
135
|
+
obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
|
|
136
|
+
prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
|
|
137
|
+
_this.setResult(obsQuery.getCurrentResult());
|
|
64
138
|
}
|
|
65
|
-
}
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
previousData: void 0,
|
|
74
|
-
watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),
|
|
75
|
-
});
|
|
76
|
-
useEffect(function () {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
|
|
79
|
-
var nextResult;
|
|
80
|
-
if (ref.current.client !== client || !equal(ref.current.query, query)) {
|
|
81
|
-
var obsQuery_1 = client.watchQuery(watchQueryOptions);
|
|
82
|
-
setObsQuery(obsQuery_1);
|
|
83
|
-
nextResult = obsQuery_1.getCurrentResult();
|
|
84
|
-
}
|
|
85
|
-
else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {
|
|
86
|
-
obsQuery.setOptions(watchQueryOptions).catch(function () { });
|
|
87
|
-
nextResult = obsQuery.getCurrentResult();
|
|
88
|
-
ref.current.watchQueryOptions = watchQueryOptions;
|
|
89
|
-
}
|
|
90
|
-
if (nextResult) {
|
|
91
|
-
var previousResult = ref.current.result;
|
|
92
|
-
if (previousResult.data) {
|
|
93
|
-
ref.current.previousData = previousResult.data;
|
|
139
|
+
}, [obsQuery, this.watchQueryOptions]);
|
|
140
|
+
return obsQuery;
|
|
141
|
+
};
|
|
142
|
+
InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
|
|
143
|
+
var _this = this;
|
|
144
|
+
useEffect(function () {
|
|
145
|
+
if (_this.renderPromises) {
|
|
146
|
+
return;
|
|
94
147
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
148
|
+
var onNext = function () {
|
|
149
|
+
var previousResult = _this.result;
|
|
150
|
+
var result = obsQuery.getCurrentResult();
|
|
151
|
+
if (previousResult &&
|
|
152
|
+
previousResult.loading === result.loading &&
|
|
153
|
+
previousResult.networkStatus === result.networkStatus &&
|
|
154
|
+
equal(previousResult.data, result.data)) {
|
|
155
|
+
return;
|
|
99
156
|
}
|
|
100
|
-
|
|
101
|
-
|
|
157
|
+
_this.setResult(result);
|
|
158
|
+
};
|
|
159
|
+
var onError = function (error) {
|
|
160
|
+
var last = obsQuery["last"];
|
|
161
|
+
subscription.unsubscribe();
|
|
162
|
+
try {
|
|
163
|
+
obsQuery.resetLastResults();
|
|
164
|
+
subscription = obsQuery.subscribe(onNext, onError);
|
|
102
165
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
166
|
+
finally {
|
|
167
|
+
obsQuery["last"] = last;
|
|
168
|
+
}
|
|
169
|
+
if (!hasOwnProperty.call(error, 'graphQLErrors')) {
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
var previousResult = _this.result;
|
|
173
|
+
if (!previousResult ||
|
|
174
|
+
(previousResult && previousResult.loading) ||
|
|
175
|
+
!equal(error, previousResult.error)) {
|
|
176
|
+
_this.setResult({
|
|
177
|
+
data: (previousResult && previousResult.data),
|
|
178
|
+
error: error,
|
|
179
|
+
loading: false,
|
|
180
|
+
networkStatus: NetworkStatus.error,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var subscription = obsQuery.subscribe(onNext, onError);
|
|
185
|
+
return function () { return subscription.unsubscribe(); };
|
|
186
|
+
}, [
|
|
187
|
+
obsQuery,
|
|
188
|
+
this.renderPromises,
|
|
189
|
+
this.client.disableNetworkFetches,
|
|
190
|
+
]);
|
|
191
|
+
};
|
|
192
|
+
InternalState.prototype.setResult = function (nextResult) {
|
|
193
|
+
var previousResult = this.result;
|
|
194
|
+
if (previousResult && previousResult.data) {
|
|
195
|
+
this.previousData = previousResult.data;
|
|
110
196
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
equal(previousResult.data, result.data)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (previousResult.data) {
|
|
123
|
-
ref.current.previousData = previousResult.data;
|
|
197
|
+
this.result = nextResult;
|
|
198
|
+
this.forceUpdate();
|
|
199
|
+
this.handleErrorOrCompleted(nextResult);
|
|
200
|
+
};
|
|
201
|
+
InternalState.prototype.handleErrorOrCompleted = function (result) {
|
|
202
|
+
if (!result.loading) {
|
|
203
|
+
if (result.error) {
|
|
204
|
+
this.onError(result.error);
|
|
124
205
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
(_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
|
|
206
|
+
else if (result.data) {
|
|
207
|
+
this.onCompleted(result.data);
|
|
128
208
|
}
|
|
129
209
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
210
|
+
};
|
|
211
|
+
InternalState.prototype.getCurrentResult = function () {
|
|
212
|
+
var result = this.result;
|
|
213
|
+
if (!result) {
|
|
214
|
+
result = this.result = this.observable.getCurrentResult();
|
|
215
|
+
this.handleErrorOrCompleted(result);
|
|
216
|
+
}
|
|
217
|
+
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
218
|
+
this.queryHookOptions.ssr === false) {
|
|
219
|
+
result = {
|
|
220
|
+
loading: true,
|
|
221
|
+
data: void 0,
|
|
222
|
+
error: void 0,
|
|
223
|
+
networkStatus: NetworkStatus.loading,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
else if (this.queryHookOptions.skip ||
|
|
227
|
+
this.queryHookOptions.fetchPolicy === 'standby') {
|
|
228
|
+
result = {
|
|
229
|
+
loading: false,
|
|
230
|
+
data: void 0,
|
|
231
|
+
error: void 0,
|
|
232
|
+
networkStatus: NetworkStatus.ready,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
};
|
|
237
|
+
InternalState.prototype.toQueryResult = function (result) {
|
|
238
|
+
var queryResult = this.toQueryResultCache.get(result);
|
|
239
|
+
if (queryResult)
|
|
240
|
+
return queryResult;
|
|
241
|
+
var data = result.data, partial = result.partial, resultWithoutPartial = __rest(result, ["data", "partial"]);
|
|
242
|
+
this.toQueryResultCache.set(result, queryResult = __assign(__assign(__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: true, previousData: this.previousData }));
|
|
243
|
+
if (!queryResult.error && isNonEmptyArray(result.errors)) {
|
|
244
|
+
queryResult.error = new ApolloError({ graphQLErrors: result.errors });
|
|
155
245
|
}
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (partial &&
|
|
162
|
-
(options === null || options === void 0 ? void 0 : options.partialRefetch) &&
|
|
246
|
+
return queryResult;
|
|
247
|
+
};
|
|
248
|
+
InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
|
|
249
|
+
if (result.partial &&
|
|
250
|
+
this.queryHookOptions.partialRefetch &&
|
|
163
251
|
!result.loading &&
|
|
164
252
|
(!result.data || Object.keys(result.data).length === 0) &&
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
253
|
+
this.observable.options.fetchPolicy !== 'cache-only') {
|
|
254
|
+
Object.assign(result, {
|
|
255
|
+
loading: true,
|
|
256
|
+
networkStatus: NetworkStatus.refetch,
|
|
257
|
+
});
|
|
258
|
+
this.observable.refetch();
|
|
168
259
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
result.loading) {
|
|
173
|
-
obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(function () { });
|
|
174
|
-
}
|
|
175
|
-
Object.assign(ref.current, { options: options });
|
|
176
|
-
}
|
|
177
|
-
if ((context.renderPromises || client.disableNetworkFetches) &&
|
|
178
|
-
(options === null || options === void 0 ? void 0 : options.ssr) === false) {
|
|
179
|
-
result = ref.current.result = {
|
|
180
|
-
loading: true,
|
|
181
|
-
data: void 0,
|
|
182
|
-
error: void 0,
|
|
183
|
-
networkStatus: NetworkStatus.loading,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
|
|
187
|
-
result = {
|
|
188
|
-
loading: false,
|
|
189
|
-
data: void 0,
|
|
190
|
-
error: void 0,
|
|
191
|
-
networkStatus: NetworkStatus.ready,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
if (result.errors && result.errors.length) {
|
|
195
|
-
result = __assign(__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
|
|
196
|
-
}
|
|
197
|
-
var obsQueryFields = useMemo(function () { return ({
|
|
198
|
-
refetch: obsQuery.refetch.bind(obsQuery),
|
|
199
|
-
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
200
|
-
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
201
|
-
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
202
|
-
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
203
|
-
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
204
|
-
}); }, [obsQuery]);
|
|
205
|
-
return __assign(__assign(__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables, client: client, called: true, previousData: ref.current.previousData }), result);
|
|
206
|
-
}
|
|
207
|
-
function createWatchQueryOptions(query, options, defaultOptions) {
|
|
208
|
-
var _a;
|
|
209
|
-
if (options === void 0) { options = {}; }
|
|
210
|
-
var skip = options.skip, ssr = options.ssr, onCompleted = options.onCompleted, onError = options.onError, displayName = options.displayName, otherOptions = __rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
|
|
211
|
-
var watchQueryOptions = __assign({ query: query }, otherOptions);
|
|
212
|
-
if (defaultOptions) {
|
|
213
|
-
watchQueryOptions = mergeOptions(defaultOptions, watchQueryOptions);
|
|
214
|
-
}
|
|
215
|
-
if (skip) {
|
|
216
|
-
watchQueryOptions.fetchPolicy = 'standby';
|
|
217
|
-
}
|
|
218
|
-
else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
|
|
219
|
-
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
220
|
-
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
221
|
-
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
222
|
-
}
|
|
223
|
-
else if (!watchQueryOptions.fetchPolicy) {
|
|
224
|
-
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
225
|
-
}
|
|
226
|
-
if (!watchQueryOptions.variables) {
|
|
227
|
-
watchQueryOptions.variables = {};
|
|
228
|
-
}
|
|
229
|
-
return watchQueryOptions;
|
|
230
|
-
}
|
|
260
|
+
};
|
|
261
|
+
return InternalState;
|
|
262
|
+
}());
|
|
231
263
|
//# sourceMappingURL=useQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAsB,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAEL,aAAa,GAKd,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,QAAQ,CAItB,KAA0D,EAC1D,OAA6C;;IAE7C,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC/C,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,IAAM,wBAAwB,GAAG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AAC,CAAC;KACrE;IAED,IAAI,IAAI,EAAE;QACR,iBAAiB,CAAC,WAAW,GAAG,SAAS,CAAC;KAC3C;SAAM,IACL,CAAA,MAAA,iBAAiB,CAAC,OAAO,0CAAE,cAAc;QACzC,CACE,iBAAiB,CAAC,WAAW,KAAK,cAAc;YAChD,iBAAiB,CAAC,WAAW,KAAK,mBAAmB,CACtD,EACD;QAGA,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;SAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE;QAGzC,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;IAED,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE;QAChC,iBAAiB,CAAC,SAAS,GAAG,EAAgB,CAAC;KAChD;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { equal } from '@wry/equality';\nimport { OperationVariables, mergeOptions } from '../../core';\nimport { getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useQuery<\n TData = any,\n TVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: QueryHookOptions<TData, TVariables>,\n): QueryResult<TData, TVariables> {\n const context = useContext(getApolloContext());\n const client = useApolloClient(options?.client);\n const defaultWatchQueryOptions = client.defaultOptions.watchQuery;\n verifyDocumentType(query, DocumentType.Query);\n const [obsQuery, setObsQuery] = useState(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n let obsQuery: ObservableQuery<TData, TVariables> | null = null;\n if (context.renderPromises) {\n obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);\n }\n\n if (!obsQuery) {\n // Is it safe (StrictMode/memory-wise) to call client.watchQuery here?\n obsQuery = client.watchQuery(watchQueryOptions);\n if (context.renderPromises) {\n context.renderPromises.registerSSRObservable(\n obsQuery,\n watchQueryOptions,\n );\n }\n }\n\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n obsQuery.getCurrentResult().loading\n ) {\n // TODO: This is a legacy API which could probably be cleaned up\n context.renderPromises.addQueryPromise(\n {\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => createWatchQueryOptions(query, options, defaultWatchQueryOptions),\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery!.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n resolve();\n },\n });\n }),\n },\n // This callback never seemed to do anything\n () => null,\n );\n }\n\n return obsQuery;\n });\n\n let [result, setResult] = useState(() => {\n const result = obsQuery.getCurrentResult();\n if (!result.loading && options) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n\n return result;\n });\n\n const ref = useRef({\n client,\n query,\n options,\n result,\n previousData: void 0 as TData | undefined,\n watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),\n });\n\n // An effect to recreate the obsQuery whenever the client or query changes.\n // This effect is also responsible for checking and updating the obsQuery\n // options whenever they change.\n useEffect(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);\n let nextResult: ApolloQueryResult<TData> | undefined;\n if (ref.current.client !== client || !equal(ref.current.query, query)) {\n const obsQuery = client.watchQuery(watchQueryOptions);\n setObsQuery(obsQuery);\n nextResult = obsQuery.getCurrentResult();\n } else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {\n obsQuery.setOptions(watchQueryOptions).catch(() => {});\n nextResult = obsQuery.getCurrentResult();\n ref.current.watchQueryOptions = watchQueryOptions;\n }\n\n if (nextResult) {\n const previousResult = ref.current.result;\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = nextResult);\n if (!nextResult.loading && options) {\n if (nextResult.error) {\n options.onError?.(nextResult.error);\n } else if (nextResult.data) {\n options.onCompleted?.(nextResult.data);\n }\n }\n }\n\n Object.assign(ref.current, { client, query });\n }, [obsQuery, client, query, options]);\n\n // An effect to subscribe to the current observable query\n useEffect(() => {\n if (context.renderPromises) {\n return;\n }\n\n let subscription = obsQuery.subscribe(onNext, onError);\n // We use `getCurrentResult()` instead of the callback argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n function onNext() {\n const previousResult = ref.current.result;\n const result = obsQuery.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = result);\n if (!result.loading) {\n ref.current.options?.onCompleted?.(result.data);\n }\n }\n\n function onError(error: Error) {\n const last = obsQuery[\"last\"];\n subscription.unsubscribe();\n // Unfortunately, if `lastError` is set in the current\n // `observableQuery` when the subscription is re-created,\n // the subscription will immediately receive the error, which will\n // cause it to terminate again. To avoid this, we first clear\n // the last error/result from the `observableQuery` before re-starting\n // the subscription, and restore it afterwards (so the subscription\n // has a chance to stay open).\n try {\n obsQuery.resetLastResults();\n subscription = obsQuery.subscribe(onNext, onError);\n } finally {\n obsQuery[\"last\"] = last;\n }\n\n if (!error.hasOwnProperty('graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = ref.current.result;\n if (\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(ref.current.result = {\n data: previousResult.data,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n ref.current.options?.onError?.(error as ApolloError);\n }\n }\n\n return () => subscription.unsubscribe();\n }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);\n\n let partial: boolean | undefined;\n ({ partial, ...result } = result);\n\n {\n // BAD BOY CODE BLOCK WHERE WE PUT SIDE-EFFECTS IN THE RENDER FUNCTION\n //\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n partial &&\n options?.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n obsQuery.options.fetchPolicy !== 'cache-only'\n ) {\n result = {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n\n obsQuery.refetch();\n }\n\n // TODO: This is a hack to make sure useLazyQuery executions update the\n // obsevable query options for ssr.\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n result.loading\n ) {\n obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(() => {});\n }\n\n // We assign options during rendering as a guard to make sure that\n // callbacks like onCompleted and onError are not stale.\n Object.assign(ref.current, { options });\n }\n\n if (\n (context.renderPromises || client.disableNetworkFetches) &&\n options?.ssr === false\n ) {\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n result = ref.current.result = {\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n };\n } else if (options?.skip || options?.fetchPolicy === 'standby') {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n result = {\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n };\n }\n\n if (result.errors && result.errors.length) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n result = {\n ...result,\n error: result.error || new ApolloError({ graphQLErrors: result.errors }),\n };\n }\n\n const obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }), [obsQuery]);\n\n return {\n ...obsQueryFields,\n variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables,\n client,\n called: true,\n previousData: ref.current.previousData,\n ...result,\n };\n}\n\n/**\n * A function to massage options before passing them the ObservableQuery.\n */\nfunction createWatchQueryOptions<TData, TVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = {},\n defaultOptions?: Partial<WatchQueryOptions<any, any>>\n): WatchQueryOptions<TVariables, TData> {\n // TODO: For some reason, we pass context, which is the React Apollo Context,\n // into observable queries, and test for that.\n // removing hook specific options\n const {\n skip,\n ssr,\n onCompleted,\n onError,\n displayName,\n ...otherOptions\n } = options;\n\n let watchQueryOptions = { query, ...otherOptions };\n if (defaultOptions) {\n watchQueryOptions = mergeOptions(defaultOptions, watchQueryOptions);\n }\n\n if (skip) {\n watchQueryOptions.fetchPolicy = 'standby';\n } else if (\n watchQueryOptions.context?.renderPromises &&\n (\n watchQueryOptions.fetchPolicy === 'network-only' ||\n watchQueryOptions.fetchPolicy === 'cache-and-network'\n )\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = 'cache-first';\n } else if (!watchQueryOptions.fetchPolicy) {\n // cache-first is the default policy, but we explicitly assign it here so\n // the cache policies computed based on options can be cleared\n watchQueryOptions.fetchPolicy = 'cache-first';\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n return watchQueryOptions;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GACjD,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAsB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAGL,aAAa,GAKd,MAAM,YAAY,CAAC;AAQpB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAI7C,IAAA,cAAc,GAEd,MAAM,yBAFQ,CAEP;AAEX,MAAM,UAAU,QAAQ,CAItB,KAA0D,EAC1D,iBAE+C;IAE/C,IAAM,OAAO,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;IACxD,OAAO,gBAAgB,CACrB,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EAC/B,KAAK,CACN,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,gBAAgB,CACvB,MAAyB,EACzB,KAA0D;IAE1D,IAAM,QAAQ,GAAG,MAAM,EAAoC,CAAC;IAC5D,I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AAM,EAAnD,mBAA0C,CAAF,CAAY;QAC1D,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,gCAC7C,IAAI,MAAA,IACD,oBAAoB,GACpB,IAAI,CAAC,cAAc,KACtB,MAAM,EAAE,IAAI,CAAC,MAAM,EACnB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,EACpC,MAAM,EAAE,IAAI,EACZ,YAAY,EAAE,IAAI,CAAC,YAAY,GAChC,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YAKxD,WAAW,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;SACvE;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,kDAA0B,GAAlC,UAAmC,MAAgC;QAMjE,IACE,MAAM,CAAC,OAAO;YACd,IAAI,CAAC,gBAAgB,CAAC,cAAc;YACpC,CAAC,MAAM,CAAC,OAAO;YACf,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;YACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,KAAK,YAAY,EACpD;YACA,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;gBACpB,OAAO,EAAE,IAAI;gBACb,aAAa,EAAE,aAAa,CAAC,OAAO;aACrC,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC3B;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAlaD,IAkaC","sourcesContent":["import {\n useContext, useEffect, useMemo, useRef, useState,\n} from 'react';\nimport { equal } from '@wry/equality';\nimport { OperationVariables } from '../../core';\nimport { ApolloContextValue, getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloClient,\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n QueryHookOptionsFunction,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\nimport { canUseWeakMap, isNonEmptyArray } from '../../utilities';\nimport { useNormalizedOptions } from './options';\n\nconst {\n prototype: {\n hasOwnProperty,\n },\n} = Object;\n\nexport function useQuery<\n TData = any,\n TVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n optionsOrFunction?:\n | QueryHookOptions<TData, TVariables>\n | QueryHookOptionsFunction<TData, TVariables>\n): QueryResult<TData, TVariables> {\n const options = useNormalizedOptions(optionsOrFunction);\n return useInternalState(\n useApolloClient(options.client),\n query,\n ).useQuery(options);\n}\n\nfunction useInternalState<TData, TVariables>(\n client: ApolloClient<any>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n) {\n const stateRef = useRef<InternalState<TData, TVariables>>();\n if (\n !stateRef.current ||\n client !== stateRef.current.client ||\n query !== stateRef.current.query\n ) {\n stateRef.current = new InternalState(client, query);\n }\n const state = stateRef.current;\n\n // By default, InternalState.prototype.forceUpdate is an empty function, but\n // we replace it here (before anyone has had a chance to see this state yet)\n // with a function that unconditionally forces an update, using the latest\n // setTick function. Updating this state by calling state.forceUpdate is the\n // only way we trigger React component updates (no other useState calls within\n // the InternalState class).\n const [_tick, setTick] = useState(0);\n state.forceUpdate = () => {\n setTick(tick => tick + 1);\n };\n\n return state;\n}\n\nclass InternalState<TData, TVariables> {\n constructor(\n public readonly client: ReturnType<typeof useApolloClient>,\n public readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ) {\n verifyDocumentType(query, DocumentType.Query);\n }\n\n public forceUpdate() {\n // Replaced (in useInternalState) with a method that triggers an update.\n }\n\n // Methods beginning with use- should be called according to the standard\n // rules of React hooks: only at the top level of the calling function, and\n // without any dynamic conditional logic.\n public useQuery(options: QueryHookOptions<TData, TVariables>) {\n this.useOptions(options);\n\n const obsQuery = this.useObservableQuery();\n this.useSubscriptionEffect(obsQuery);\n\n const result = this.getCurrentResult();\n\n // TODO Remove this method when we remove support for options.partialRefetch.\n this.unsafeHandlePartialRefetch(result);\n\n return this.toQueryResult(result);\n }\n\n // These members are all populated by the useOptions method, which is called\n // unconditionally at the beginning of the useQuery method, so we can safely\n // use these members in other/later methods without worrying about the\n // possibility they might be undefined.\n private renderPromises: ApolloContextValue[\"renderPromises\"];\n private queryHookOptions: QueryHookOptions<TData, TVariables>;\n private watchQueryOptions: WatchQueryOptions<TVariables, TData>;\n private ssrDisabled: boolean;\n\n private useOptions(\n options: QueryHookOptions<TData, TVariables>,\n ) {\n this.renderPromises = useContext(getApolloContext()).renderPromises;\n\n const watchQueryOptions = this.createWatchQueryOptions(\n this.queryHookOptions = options,\n );\n // Update this.watchQueryOptions, but only when they have changed, which\n // allows us to depend on the referential stability of\n // this.watchQueryOptions elsewhere.\n if (!equal(watchQueryOptions, this.watchQueryOptions)) {\n this.watchQueryOptions = watchQueryOptions;\n }\n\n this.ssrDisabled = !!(options && (\n options.ssr === false ||\n options.skip\n ));\n\n // Make sure state.onCompleted and state.onError always reflect the latest\n // options.onCompleted and options.onError callbacks provided to useQuery,\n // since those functions are often recreated every time useQuery is called.\n // Like the forceUpdate method, the versions of these methods inherited from\n // InternalState.prototype are empty no-ops, but we can override them on the\n // base state object (without modifying the prototype).\n\n this.onCompleted = options\n && options.onCompleted\n || InternalState.prototype.onCompleted;\n\n this.onError = options\n && options.onError\n || InternalState.prototype.onError;\n }\n\n // A function to massage options before passing them to ObservableQuery.\n private createWatchQueryOptions<TData, TVariables>({\n skip,\n ssr,\n onCompleted,\n onError,\n displayName,\n // The above options are useQuery-specific, so this ...otherOptions spread\n // makes otherOptions almost a WatchQueryOptions object, except for the\n // query property that we add below.\n ...otherOptions\n }: QueryHookOptions<TData, TVariables> = {}): WatchQueryOptions<TVariables, TData> {\n // TODO: For some reason, we pass context, which is the React Apollo Context,\n // into observable queries, and test for that.\n const watchQueryOptions: WatchQueryOptions<TVariables, TData> =\n Object.assign(otherOptions, { query: this.query });\n\n if (skip) {\n watchQueryOptions.fetchPolicy = 'standby';\n } else if (\n watchQueryOptions.context?.renderPromises &&\n (\n watchQueryOptions.fetchPolicy === 'network-only' ||\n watchQueryOptions.fetchPolicy === 'cache-and-network'\n )\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = 'cache-first';\n } else if (!watchQueryOptions.fetchPolicy) {\n const defaultOptions = this.client.defaultOptions.watchQuery;\n // cache-first is the default policy, but we explicitly assign it here so\n // the cache policies computed based on options can be cleared\n watchQueryOptions.fetchPolicy =\n defaultOptions && defaultOptions.fetchPolicy || 'cache-first';\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n return watchQueryOptions;\n }\n\n // Defining these methods as no-ops on the prototype allows us to call\n // state.onCompleted and/or state.onError without worrying about whether a\n // callback was provided.\n private onCompleted(data: TData) {}\n private onError(error: ApolloError) {}\n\n private observable: ObservableQuery<TData, TVariables>;\n private obsQueryFields: Omit<\n ObservableQueryFields<TData, TVariables>,\n \"variables\"\n >;\n\n private useObservableQuery() {\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n const obsQuery = this.observable =\n this.renderPromises\n && this.renderPromises.getSSRObservable(this.watchQueryOptions)\n || this.observable // Reuse this.observable if possible (and not SSR)\n || this.client.watchQuery(this.watchQueryOptions);\n\n this.obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }), [obsQuery]);\n\n if (this.renderPromises) {\n this.renderPromises.registerSSRObservable(obsQuery);\n\n if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n this.renderPromises.addQueryPromise({\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => obsQuery.options,\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n resolve();\n },\n });\n }),\n },\n // This callback never seemed to do anything\n () => null);\n\n // TODO: This is a hack to make sure useLazyQuery executions update the\n // obsevable query options for ssr.\n obsQuery.setOptions(this.watchQueryOptions).catch(() => {});\n }\n }\n\n const prevOptionsRef = useRef({\n watchQueryOptions: this.watchQueryOptions,\n });\n\n // An effect to keep obsQuery.options up to date in case\n // state.watchQueryOptions changes.\n useEffect(() => {\n if (this.renderPromises) {\n // Do nothing during server rendering.\n } else if (\n // The useOptions method only updates this.watchQueryOptions if new new\n // watchQueryOptions are not deep-equal to the previous options, so we\n // only need a reference check (!==) here.\n this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions\n ) {\n obsQuery.setOptions(this.watchQueryOptions).catch(() => {});\n prevOptionsRef.current.watchQueryOptions = this.watchQueryOptions;\n this.setResult(obsQuery.getCurrentResult());\n }\n }, [obsQuery, this.watchQueryOptions]);\n\n return obsQuery;\n }\n\n private useSubscriptionEffect(\n // We could use this.observable and not pass this obsQuery parameter, but I\n // like the guarantee that obsQuery won't change, whereas this.observable\n // could change without warning (in theory).\n obsQuery: ObservableQuery<TData, TVariables>,\n ) {\n // An effect to subscribe to the current observable query\n useEffect(() => {\n if (this.renderPromises) {\n return;\n }\n\n const onNext = () => {\n const previousResult = this.result;\n // We use `getCurrentResult()` instead of the onNext argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n const result = obsQuery.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n this.setResult(result);\n };\n\n const onError = (error: Error) => {\n const last = obsQuery[\"last\"];\n subscription.unsubscribe();\n // Unfortunately, if `lastError` is set in the current\n // `observableQuery` when the subscription is re-created,\n // the subscription will immediately receive the error, which will\n // cause it to terminate again. To avoid this, we first clear\n // the last error/result from the `observableQuery` before re-starting\n // the subscription, and restore it afterwards (so the subscription\n // has a chance to stay open).\n try {\n obsQuery.resetLastResults();\n subscription = obsQuery.subscribe(onNext, onError);\n } finally {\n obsQuery[\"last\"] = last;\n }\n\n if (!hasOwnProperty.call(error, 'graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = this.result;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n this.setResult({\n data: (previousResult && previousResult.data) as TData,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n }\n };\n\n let subscription = obsQuery.subscribe(onNext, onError);\n\n return () => subscription.unsubscribe();\n }, [\n obsQuery,\n this.renderPromises,\n this.client.disableNetworkFetches,\n ]);\n }\n\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n private result: undefined | ApolloQueryResult<TData>;\n private previousData: undefined | TData;\n\n private setResult(nextResult: ApolloQueryResult<TData>) {\n const previousResult = this.result;\n if (previousResult && previousResult.data) {\n this.previousData = previousResult.data;\n }\n this.result = nextResult;\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n this.forceUpdate();\n this.handleErrorOrCompleted(nextResult);\n }\n\n private handleErrorOrCompleted(result: ApolloQueryResult<TData>) {\n if (!result.loading) {\n if (result.error) {\n this.onError(result.error);\n } else if (result.data) {\n this.onCompleted(result.data);\n }\n }\n }\n\n private getCurrentResult(): ApolloQueryResult<TData> {\n let { result } = this;\n // Using this.result as a cache ensures getCurrentResult continues returning\n // the same (===) result object, unless state.setResult has been called, or\n // we're doing server rendering and therefore override the result below.\n if (!result) {\n result = this.result = this.observable.getCurrentResult();\n this.handleErrorOrCompleted(result);\n }\n\n if (\n (this.renderPromises || this.client.disableNetworkFetches) &&\n this.queryHookOptions.ssr === false\n ) {\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n result = {\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n };\n } else if (\n this.queryHookOptions.skip ||\n this.queryHookOptions.fetchPolicy === 'standby'\n ) {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n result = {\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n };\n }\n\n return result;\n }\n\n // This cache allows the referential stability of this.result (as returned by\n // getCurrentResult) to translate into referential stability of the resulting\n // QueryResult object returned by toQueryResult.\n private toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)<\n ApolloQueryResult<TData>,\n QueryResult<TData, TVariables>\n >();\n\n private toQueryResult(\n result: ApolloQueryResult<TData>,\n ): QueryResult<TData, TVariables> {\n let queryResult = this.toQueryResultCache.get(result);\n if (queryResult) return queryResult;\n\n const { data, partial, ...resultWithoutPartial } = result;\n this.toQueryResultCache.set(result, queryResult = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n ...this.obsQueryFields,\n client: this.client,\n observable: this.observable,\n variables: this.observable.variables,\n called: true,\n previousData: this.previousData,\n });\n\n if (!queryResult.error && isNonEmptyArray(result.errors)) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n queryResult.error = new ApolloError({ graphQLErrors: result.errors });\n }\n\n return queryResult;\n }\n\n private unsafeHandlePartialRefetch(result: ApolloQueryResult<TData>) {\n // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION\n //\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n result.partial &&\n this.queryHookOptions.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n this.observable.options.fetchPolicy !== 'cache-only'\n ) {\n Object.assign(result, {\n loading: true,\n networkStatus: NetworkStatus.refetch,\n });\n this.observable.refetch();\n }\n }\n}\n"]}
|
|
@@ -10,7 +10,7 @@ export declare class RenderPromises {
|
|
|
10
10
|
private queryInfoTrie;
|
|
11
11
|
private stopped;
|
|
12
12
|
stop(): void;
|
|
13
|
-
registerSSRObservable<TData, TVariables>(observable: ObservableQuery<any, TVariables
|
|
13
|
+
registerSSRObservable<TData, TVariables>(observable: ObservableQuery<any, TVariables>): void;
|
|
14
14
|
getSSRObservable<TData, TVariables>(props: QueryDataOptions<TData, TVariables>): ObservableQuery<any, TVariables> | null;
|
|
15
15
|
addQueryPromise(queryInstance: QueryData, finish: () => React.ReactNode): React.ReactNode;
|
|
16
16
|
hasPromises(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderPromises.d.ts","sourceRoot":"","sources":["../../../src/react/ssr/RenderPromises.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlD,UAAU,SAAS;IACjB,UAAU,IAAI,GAAG,CAAC;IAClB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAcD,qBAAa,cAAc;IAEzB,OAAO,CAAC,aAAa,CAAuD;IAM5E,OAAO,CAAC,aAAa,CAAmD;IAExE,OAAO,CAAC,OAAO,CAAS;IACjB,IAAI;IASJ,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAC5C,UAAU,EAAE,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"RenderPromises.d.ts","sourceRoot":"","sources":["../../../src/react/ssr/RenderPromises.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlD,UAAU,SAAS;IACjB,UAAU,IAAI,GAAG,CAAC;IAClB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAcD,qBAAa,cAAc;IAEzB,OAAO,CAAC,aAAa,CAAuD;IAM5E,OAAO,CAAC,aAAa,CAAmD;IAExE,OAAO,CAAC,OAAO,CAAS;IACjB,IAAI;IASJ,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAC5C,UAAU,EAAE,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC;IAOvC,gBAAgB,CAAC,KAAK,EAAE,UAAU,EACvC,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,GACzC,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,IAAI;IAInC,eAAe,CACpB,aAAa,EAAE,SAAS,EACxB,MAAM,EAAE,MAAM,KAAK,CAAC,SAAS,GAC5B,KAAK,CAAC,SAAS;IAkBX,WAAW;IAIX,uBAAuB;IAmB9B,OAAO,CAAC,eAAe;CAYxB"}
|
|
@@ -17,10 +17,10 @@ var RenderPromises = (function () {
|
|
|
17
17
|
this.stopped = true;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
RenderPromises.prototype.registerSSRObservable = function (observable
|
|
20
|
+
RenderPromises.prototype.registerSSRObservable = function (observable) {
|
|
21
21
|
if (this.stopped)
|
|
22
22
|
return;
|
|
23
|
-
this.lookupQueryInfo(
|
|
23
|
+
this.lookupQueryInfo(observable.options).observable = observable;
|
|
24
24
|
};
|
|
25
25
|
RenderPromises.prototype.getSSRObservable = function (props) {
|
|
26
26
|
return this.lookupQueryInfo(props).observable;
|