@apollo/client 4.2.0-alpha.7 → 4.2.0-alpha.8
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/CHANGELOG.md +39 -0
- package/__cjs/core/ApolloClient.cjs +27 -7
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +9 -1
- package/__cjs/core/RefetchEventManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.d.cts +10 -0
- package/__cjs/invariantErrorCodes.cjs +1 -1
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.js +27 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/RefetchEventManager.d.ts +10 -0
- package/core/RefetchEventManager.js +9 -1
- package/core/RefetchEventManager.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +1 -1
- package/version.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @apollo/client
|
|
2
2
|
|
|
3
|
+
## 4.2.0-alpha.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#13229](https://github.com/apollographql/apollo-client/pull/13229) [`9a7f65a`](https://github.com/apollographql/apollo-client/commit/9a7f65a0059433c83307ef2d8117dac67947d791) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix `refetchOn` merging when `defaultOptions.watchQuery.refetchOn` is set to a non-object value (`false`, `true`, or a function) and the per-query `refetchOn` is an object. Previously the per-query object completely replaced the default so unspecified events fell back to "enabled" regardless of the default.
|
|
8
|
+
|
|
9
|
+
The `defaultOptions` value now applies to any event the per-query object does not explicitly configure:
|
|
10
|
+
|
|
11
|
+
- `false` - unspecified events stay disabled
|
|
12
|
+
- `true` - unspecified events refetch
|
|
13
|
+
- Callback function - the function is called for unspecified events to determine whether to refetch
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const client = new ApolloClient({
|
|
17
|
+
// ...
|
|
18
|
+
defaultOptions: {
|
|
19
|
+
watchQuery: {
|
|
20
|
+
refetchOn: false,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Only `windowFocus` refetches. Other events stay disabled per the default.
|
|
26
|
+
useQuery(QUERY, { refetchOn: { windowFocus: true } });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- [#13230](https://github.com/apollographql/apollo-client/pull/13230) [`b25b659`](https://github.com/apollographql/apollo-client/commit/b25b6593f5d968db505b127e7ff7f2bb2419d5ee) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Add the ability to override the default event handler on `RefetchEventManager`. The default handler runs when no per-source handler is configured for an event. Provide a custom handler via the `defaultHandler` constructor option or the `setDefaultEventHandler` instance method.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
new RefetchEventManager({
|
|
33
|
+
defaultHandler: ({ client, matchesRefetchOn }) => {
|
|
34
|
+
return client.refetchQueries({
|
|
35
|
+
include: "all",
|
|
36
|
+
onQueryUpdated: matchesRefetchOn,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
3
42
|
## 4.2.0-alpha.7
|
|
4
43
|
|
|
5
44
|
### Minor Changes
|
|
@@ -229,22 +229,42 @@ class ApolloClient {
|
|
|
229
229
|
* a description of store reactivity.
|
|
230
230
|
*/
|
|
231
231
|
watchQuery(options) {
|
|
232
|
+
const { refetchOn } = options;
|
|
232
233
|
if (this.defaultOptions.watchQuery) {
|
|
234
|
+
// Capture the default `refetchOn` at the time of the `watchQuery`
|
|
235
|
+
// call so that it is unaffected even if defaultOptions.refetchOn is
|
|
236
|
+
// mutated later.
|
|
233
237
|
const defaultRefetchOn = this.defaultOptions.watchQuery.refetchOn;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
defaultRefetchOn
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
let mergedRefetchOn;
|
|
239
|
+
if (refetchOn && typeof refetchOn === "object") {
|
|
240
|
+
if (typeof defaultRefetchOn === "object") {
|
|
241
|
+
mergedRefetchOn = { ...defaultRefetchOn, ...refetchOn };
|
|
242
|
+
}
|
|
243
|
+
else if (defaultRefetchOn != null) {
|
|
244
|
+
// We set the merged `refetchOn` option to a callback function in case
|
|
245
|
+
// the client hasn't connected to a RefetchEventManager yet, or
|
|
246
|
+
// sources are added to the manager after watchQuery is called. This
|
|
247
|
+
// ensures we can handle any registered source regardless of when it
|
|
248
|
+
// was registered.
|
|
249
|
+
mergedRefetchOn = (ctx) => {
|
|
250
|
+
const value = refetchOn[ctx.source] ?? defaultRefetchOn;
|
|
251
|
+
if (typeof value === "function") {
|
|
252
|
+
return value(ctx);
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
240
258
|
options = (0, internal_1.mergeOptions)(this.defaultOptions.watchQuery, options);
|
|
241
259
|
if (mergedRefetchOn) {
|
|
242
260
|
options.refetchOn = mergedRefetchOn;
|
|
243
261
|
}
|
|
244
262
|
}
|
|
245
263
|
if (environment_1.__DEV__) {
|
|
246
|
-
const {
|
|
264
|
+
const { query } = options;
|
|
247
265
|
const { refetchEventManager } = this;
|
|
266
|
+
// Note: refetchOn evaluates the original refetchOn value, not the merged
|
|
267
|
+
// refetchOn value.
|
|
248
268
|
if (refetchOn) {
|
|
249
269
|
const operationName = (0, internal_1.getOperationName)(query, "(anonymous)");
|
|
250
270
|
if (!refetchEventManager) {
|