( props: MutationProps<Url, Method, Paths> )
| 227 | ) as MutationFn; |
| 228 | }; |
| 229 | export const useApiMutation = < |
| 230 | Url extends keyof Paths, |
| 231 | Method extends keyof Paths[Url], |
| 232 | Paths = paths |
| 233 | >( |
| 234 | props: MutationProps<Url, Method, Paths> |
| 235 | ) => { |
| 236 | const queryClient = useQueryClient(); |
| 237 | const { url, method, fetchOptions, options, invalidatePrefix } = props; |
| 238 | |
| 239 | // inject custom onSuccess |
| 240 | const customOptions = getApiMutationOptions(invalidatePrefix, queryClient); |
| 241 | |
| 242 | const mutation = useMutation< |
| 243 | ResponseContent<Url, Method, Paths>, |
| 244 | ApiError, |
| 245 | RequestParamsType<Url, Method, Paths> |
| 246 | >( |
| 247 | (request) => |
| 248 | apiSchemaHttpService.schemaRequest<Url, Method, Paths>(url, method, { |
| 249 | ...fetchOptions, |
| 250 | disableAutoErrorHandle: true, |
| 251 | })(request), |
| 252 | customOptions(options as any) as any |
| 253 | ); |
| 254 | |
| 255 | const mutate = getMutationCallback( |
| 256 | mutation.mutate, |
| 257 | customOptions, |
| 258 | fetchOptions, |
| 259 | props |
| 260 | ); |
| 261 | |
| 262 | const mutateAsync = getMutationCallback( |
| 263 | mutation.mutateAsync, |
| 264 | customOptions, |
| 265 | fetchOptions, |
| 266 | props |
| 267 | ); |
| 268 | |
| 269 | return { ...mutation, mutate, mutateAsync }; |
| 270 | }; |
| 271 | |
| 272 | export const matchUrlPrefix = (prefix: string) => { |
| 273 | return { |
no test coverage detected