@@ -1219,18 +1219,36 @@ module.exports = {
1219
1219
``` ts
1220
1220
// custom-mutator-options.ts
1221
1221
1222
- export const useCustomMutatorOptions = <T , TError , TData , TContext >(
1223
- options : UseMutationOptions <T , TError , TData , TContext > &
1224
- Required <
1225
- Pick <UseMutationOptions <T , TError , TData , TContext >, ' mutationFn' >
1226
- >,
1227
- /* Optional */ path : { url: string },
1228
- /* Optional */ operation : { operationId: string ; operationName: string },
1229
- ) => {
1222
+ // custom-mutator-options.ts
1223
+ type OptionsWithMutationFn <
1224
+ TData = unknown ,
1225
+ TError = Error ,
1226
+ TVariables = void ,
1227
+ TContext = unknown ,
1228
+ > = UseMutationOptions <T , TError , TData , TContext > &
1229
+ Required <Pick <UseMutationOptions <T , TError , TData , TContext >, ' mutationFn' >>;
1230
+
1231
+ export const useCustomMutatorOptions = <
1232
+ TData = unknown ,
1233
+ TError = Error ,
1234
+ TVariables = void ,
1235
+ TContext = unknown ,
1236
+ >(
1237
+ options : OptionsWithMutationFn <T , TError , TData , TContext >,
1238
+ ): OptionsWithMutationFn <T , TError , TData , TContext > => {
1230
1239
const queryClient = useQueryClient ();
1231
- if (operation .operationId === ' createPet' ) {
1232
- queryClient .invalidateQueries ({ queryKey: getGetPetsQueryKey () });
1240
+ if (options .mutationKey ?.[0 ] === ' petDestroy' ) {
1241
+ // Note: `options.mutationKey?.[0]` is untyped.
1242
+ options .onSuccess = (_data , variables , _context ) => {
1243
+ // Note: `variables` is untyped.
1244
+ options .onSuccess ?.(data , variables , context );
1245
+ // Note: `queryKey` is hardcoded, can't use `getGetPetQueryKey()` as it would introduce circular dependencies.
1246
+ queryClient .invalidateQueries ({
1247
+ queryKey: [' api' , ' v2' , ' pet' , variables .id ],
1248
+ });
1249
+ };
1233
1250
}
1251
+ // TODO: add more ifs for each mutation.
1234
1252
return options ;
1235
1253
};
1236
1254
```
0 commit comments