1
1
import {
2
2
type UseMutationOptions ,
3
+ type QueryKey ,
3
4
useMutation ,
4
5
useQueryClient ,
5
6
} from "@tanstack/react-query" ;
@@ -10,15 +11,15 @@ import {
10
11
type QueryRef ,
11
12
executeMutation ,
12
13
} from "firebase/data-connect" ;
13
- import type { FlattenedMutationResult } from "./types" ;
14
+ import { isQueryKey , type FlattenedMutationResult } from "./types" ;
14
15
15
16
export type useDataConnectMutationOptions <
16
17
TData = unknown ,
17
18
TError = FirebaseError ,
18
- Variables = unknown ,
19
+ Variables = unknown
19
20
> = Omit < UseMutationOptions < TData , TError , Variables > , "mutationFn" > & {
20
- invalidate ?: Array <
21
- QueryRef < unknown , unknown > | ( ( ) => QueryRef < unknown , unknown > )
21
+ invalidate ?: ReadonlyArray <
22
+ QueryRef < unknown , unknown > | ( ( ) => QueryRef < unknown , unknown > ) | QueryKey
22
23
> ;
23
24
} ;
24
25
@@ -27,19 +28,19 @@ export function useDataConnectMutation<
27
28
Data = ReturnType < Fn > extends MutationRef < infer D , any > ? D : never ,
28
29
Variables = Fn extends (
29
30
dc : DataConnect ,
30
- vars : infer V ,
31
+ vars : infer V
31
32
) => MutationRef < any , any >
32
33
? V
33
34
: Fn extends ( vars : infer V ) => MutationRef < any , any >
34
- ? V
35
- : never ,
35
+ ? V
36
+ : never
36
37
> (
37
38
ref : Fn ,
38
39
options ?: useDataConnectMutationOptions <
39
40
FlattenedMutationResult < Data , Variables > ,
40
41
FirebaseError ,
41
42
Variables
42
- > ,
43
+ >
43
44
) {
44
45
const queryClient = useQueryClient ( ) ;
45
46
@@ -57,6 +58,10 @@ export function useDataConnectMutation<
57
58
queryKey : [ ref . name , ref . variables ] ,
58
59
exact : true ,
59
60
} ) ;
61
+ } else if ( isQueryKey ( ref ) ) {
62
+ queryClient . invalidateQueries ( {
63
+ queryKey : ref ,
64
+ } ) ;
60
65
} else {
61
66
queryClient . invalidateQueries ( {
62
67
queryKey : [ ref . name ] ,
0 commit comments