invertase / invertase/tanstack-query-firebase
Query invalidation in mutations does not work properly
- Dominant language
- TypeScript
- Stars
- 462
- Forks
- 69
- PR merge metrics
- No merged PRs in 30d
Description
## Current Behavior
In the DataConnect React library, query invalidation in mutations doesn't work as described when passing in a reference instance _without_ parameters.
As described in the [documentation](https://react-query-firebase.invertase.dev/react/data-connect/mutations#invalidating-queries), if I pass in just the reference to the query, it should invalidate **all** queries cached:
```ts
const createMovie = useDataConnectMutation(createMovieRef, {
invalidate: [getMovieRef],
});
```
This will actually also trigger a TypeScript error:
```
Type 'GetMovieRef' is not assignable to type 'QueryRef | (() => QueryRef)'.
Type 'GetMovieRef' is not assignable to type '() => QueryRef'.
Target signature provides too few arguments. Expected 1 or more, but got 0.ts(2322)
```
Even after ignoring the TS error, the query does **not** get invalidated after the mutation executes in the app.
However, it works as intended if a parameter is specified to invalidate a specific record:
```ts
const createMovie = useDataConnectMutation(createMovieRef, {
invalidate: [getMovieRef({ id: "1" })],
});
```
## Expected Behavior
Passing in a query reference without parameters to the `invalidate` option in mutations should invalidate **ALL** of its cached queries.
Contributor guide
Assessment
This issue has not been assessed yet.