You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rtk-query/usage/automated-refetching.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,7 @@ By declaring these tags as what can possibly be provided to the cache, it enable
108
108
109
109
### Providing cache data
110
110
111
-
Each individual `query` endpoint can have its cached data _provide_ particular tags. Doing so enables a relationship between cached data from one or more query endpoints and the behaviour of one or more mutation endpoints.
111
+
Each individual `query` endpoint can have its cached data _provide_ particular tags. Doing so enables a relationship between cached data from one or more query endpoints and the behavior of one or more mutation endpoints.
112
112
113
113
The `providesTags` property on a `query` endpoint is used for this purpose.
114
114
@@ -237,7 +237,7 @@ In order to provide stronger control over invalidating the appropriate data, you
237
237
238
238
### Invalidating cache data
239
239
240
-
Each individual mutation endpoint can `invalidate` particular tags for existing cached data. Doing so enables a relationship between cached data from one or more query endpoints and the behaviour of one or more mutation endpoints.
240
+
Each individual mutation endpoint can `invalidate` particular tags for existing cached data. Doing so enables a relationship between cached data from one or more query endpoints and the behavior of one or more mutation endpoints.
241
241
242
242
The `invalidatesTags` property on a mutation endpoint is used for this purpose.
243
243
@@ -621,7 +621,7 @@ A powerful use-case is to use an ID like `'LIST'` as a label for data provided b
621
621
622
622
:::
623
623
624
-
We can compare the scenarios below to see how using a `'LIST'` id can be leveraged to optimize behaviour.
624
+
We can compare the scenarios below to see how using a `'LIST'` id can be leveraged to optimize behavior.
625
625
626
626
#### Invalidating everything of a type
627
627
@@ -774,7 +774,7 @@ If you intend for the `addPost` mutation to refresh all posts including individu
774
774
775
775
The information provided to the cache is not limited to successful data fetches. The concept can be used to inform RTK Query that when a particular failure has been encountered, to `provide` a specific `tag` for that failed cache data. A separate endpoint can then `invalidate` the data for that `tag`, telling RTK Query to re-attempt the previously failed endpoints if a component is still subscribed to the failed data.
776
776
777
-
The example below demonstrates an example with the following behaviour:
777
+
The example below demonstrates an example with the following behavior:
778
778
779
779
- Provides an `UNAUTHORIZED` cache tag if a query fails with an error code of `401 UNAUTHORIZED`
780
780
- Provides an `UNKNOWN_ERROR` cache tag if a query fails with a different error
A key feature of RTK Query is its management of cached data. When data is fetched from the server, RTK Query will store the data in the Redux store as a 'cache'. When an additional request is performed for the same data, RTK Query will provide the existing cached data rather than sending an additional request to the server.
14
14
15
-
RTK Query provides a number of concepts and tools to manipulate the cache behaviour and adjust it to your needs.
15
+
RTK Query provides a number of concepts and tools to manipulate the cache behavior and adjust it to your needs.
16
16
17
17
## Default Cache Behavior
18
18
@@ -73,7 +73,7 @@ If 'ComponentThree' is unmounted in the example above, regardless of how much ti
73
73
74
74
## Manipulating Cache Behavior
75
75
76
-
On top of the default behaviour, RTK Query provides a number of methods to re-fetch data earlier in scenarios where it should be considered invalid, or is otherwise deemed suitable to be 'refreshed'.
76
+
On top of the default behavior, RTK Query provides a number of methods to re-fetch data earlier in scenarios where it should be considered invalid, or is otherwise deemed suitable to be 'refreshed'.
77
77
78
78
### Reducing subscription time with `keepUnusedDataFor`
If your OpenAPI specification uses [tags](https://swagger.io/docs/specification/grouping-operations-with-tags/), you can specify the `tag` option to the codegen.
67
+
If your OpenAPI specification uses [tags](https://swagger.io/docs/specification/grouping-operations-with-tags/), you can specify the `tag` option to the codegen.
68
68
That will result in all generated endpoints having `providesTags`/`invalidatesTags` declarations for the `tags` of their respective operation definition.
69
69
70
70
Note that this will only result in string tags with no ids, so it might lead to scenarios where too much is invalidated and unneccessary requests are made on mutation.
You can also filter the parameters that are included for an endpoint, as long as they aren't a path parameter. This filter is of type `ParameterMatcher`. For example, to only include parameters that begin with "x-" for the 'loginUser' endpoint, see the below example.
152
+
153
+
```ts no-transpile title="openapi-config.ts"
154
+
const withOverride:ConfigFile= {
155
+
// ...
156
+
endpointOverrides: [
157
+
{
158
+
pattern: 'loginUser',
159
+
parameterFilter:/^x-/,
160
+
},
161
+
],
162
+
}
163
+
```
164
+
165
+
For more complex requirements, consider the other possible matchers, such as a `ParameterMatcherFunction`. The below example filters out any parameters that are in the header of the request.
Setting `hooks: true` will generate `useQuery` and `useMutation` hook exports. If you also want `useLazyQuery` hooks generated or more granular control, you can also pass an object in the shape of: `{ queries: boolean; lazyQueries: boolean; mutations: boolean }`.
@@ -169,3 +199,24 @@ const config: ConfigFile = {
169
199
},
170
200
}
171
201
```
202
+
203
+
#### Custom HTTP resolver options
204
+
205
+
If you need to customize the HTTP request issued to your server, you user the `httpResolverOptions` option. This object is passed directly to the `SwaggerParser` instance that fetches the OpenAPI schema.
206
+
207
+
For example, you can pass custom headers or set a custom request timeout.
0 commit comments