Custom Operations Configuration

Finally, let's take a look at how we can add custom overrides on a per-Operation basis.

Add a custom caching configuration

This example sets reasonable defaults for caching, but disables Additionally, we're enabling caching for the Albums Query.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// wundergraph.operations.ts
import { configureWunderGraphOperations } from '@wundergraph/sdk';
import type { OperationsConfiguration } from './generated/wundergraph.operations';
export default configureWunderGraphOperations<OperationsConfiguration>({
operations: {
queries: (config) => ({
...config,
caching: {
enable: false,
staleWhileRevalidate: 60,
maxAge: 60,
public: true,
},
}),
custom: {
Albums: (config) => ({
...config,
caching: {
...config.caching,
enable: true,
},
}),
},
},
});

Add a custom live query configuration

In this example, we're enabling live queries and setting the polling interval to 10 seconds by default. On the Albums Query, we're overriding the default polling interval to 1 second.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// wundergraph.operations.ts
import { configureWunderGraphOperations } from '@wundergraph/sdk';
import type { OperationsConfiguration } from './generated/wundergraph.operations';
export default configureWunderGraphOperations<OperationsConfiguration>({
operations: {
queries: (config) => ({
...config,
liveQuery: {
enable: true,
pollingIntervalSeconds: 10,
},
}),
custom: {
Albums: (config) => ({
...config,
liveQuery: {
...config.liveQuery,
pollingIntervalSeconds: 1,
},
}),
},
},
});

Was this article helpful to you?
Provide feedback

Edit this page