From cf95da44b54dc36a4221cb323d04d7a1718d9f56 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sat, 9 Mar 2024 19:09:18 +0100 Subject: [PATCH] chore: cleanup --- examples/react-query-v5/kubb.config.ts | 2 ++ examples/react-query-v5/src/gen/hooks/useAddPetHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/useCreateUserHook.ts | 10 ++++++++++ .../src/gen/hooks/useCreateUsersWithListInputHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/useDeleteOrderHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/useDeletePetHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/useDeleteUserHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/usePlaceOrderHook.ts | 10 ++++++++++ .../src/gen/hooks/usePlaceOrderPatchHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/useUpdatePetHook.ts | 10 ++++++++++ .../src/gen/hooks/useUpdatePetWithFormHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/useUpdateUserHook.ts | 10 ++++++++++ .../react-query-v5/src/gen/hooks/useUploadFileHook.ts | 10 ++++++++++ 13 files changed, 122 insertions(+) diff --git a/examples/react-query-v5/kubb.config.ts b/examples/react-query-v5/kubb.config.ts index d43d89f90..e53073f3c 100644 --- a/examples/react-query-v5/kubb.config.ts +++ b/examples/react-query-v5/kubb.config.ts @@ -5,6 +5,7 @@ import createSwaggerTS from '@kubb/swagger-ts' import * as queryKey from './templates/queryKey/index' import * as operations from './templates/operations/index' +import * as mutation from './templates/mutate/index' /** @type {import('@kubb/core').UserConfig} */ export const config = { @@ -60,6 +61,7 @@ export const config = { }], templates: { operations: operations.templates, + mutation: mutation.templates, }, }), ], diff --git a/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts b/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts index 8e9e1a3aa..259b59cce 100644 --- a/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../models/AddPet' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useAddPetHook(options: { client?: AddPet['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useAddPetHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function useAddPetHook(options: { }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts b/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts index 090f2f4cb..523495e21 100644 --- a/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../models/CreateUser' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useCreateUserHook(options: { client?: CreateUser['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useCreateUserHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function useCreateUserHook(options: { }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts b/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts index 712ab7678..4ea07ce2b 100644 --- a/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { CreateUsersWithListInputMutationRequest, CreateUsersWithListInputMutationResponse } from '../models/CreateUsersWithListInput' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useCreateUsersWithListInputHook(options: { client?: CreateUsersWithListInput['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useCreateUsersWithListInputHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function useCreateUsersWithListInputHook(options: { }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts b/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts index d23039648..c0c8c5b4f 100644 --- a/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404 } from '../models/DeleteOrder' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useDeleteOrderHook(orderId: DeleteOrderPathParams['orderId'], op client?: DeleteOrder['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useDeleteOrderHook') return useMutation({ mutationFn: async () => { const res = await client({ @@ -35,6 +37,14 @@ export function useDeleteOrderHook(orderId: DeleteOrderPathParams['orderId'], op }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts b/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts index 71455d09d..4d0629cd5 100644 --- a/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../models/DeletePet' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useDeletePetHook(petId: DeletePetPathParams['petId'], headers?: client?: DeletePet['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useDeletePetHook') return useMutation({ mutationFn: async () => { const res = await client({ @@ -36,6 +38,14 @@ export function useDeletePetHook(petId: DeletePetPathParams['petId'], headers?: }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts b/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts index e5cbaaede..aeb466020 100644 --- a/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, DeleteUser404 } from '../models/DeleteUser' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useDeleteUserHook(username: DeleteUserPathParams['username'], op client?: DeleteUser['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useDeleteUserHook') return useMutation({ mutationFn: async () => { const res = await client({ @@ -35,6 +37,14 @@ export function useDeleteUserHook(username: DeleteUserPathParams['username'], op }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts b/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts index a6767827f..5bafd48b5 100644 --- a/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts +++ b/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { PlaceOrderMutationRequest, PlaceOrderMutationResponse, PlaceOrder405 } from '../models/PlaceOrder' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function usePlaceOrderHook(options: { client?: PlaceOrder['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('usePlaceOrderHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function usePlaceOrderHook(options: { }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts b/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts index b0bfa3bc0..7b4d1ab8d 100644 --- a/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts +++ b/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, PlaceOrderPatch405 } from '../models/PlaceOrderPatch' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function usePlaceOrderPatchHook(options: { client?: PlaceOrderPatch['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('usePlaceOrderPatchHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function usePlaceOrderPatchHook(options: { }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts b/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts index 509f41ed0..ff0959c4b 100644 --- a/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { UpdatePetMutationRequest, UpdatePetMutationResponse, UpdatePet400, UpdatePet404, UpdatePet405 } from '../models/UpdatePet' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useUpdatePetHook(options: { client?: UpdatePet['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useUpdatePetHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function useUpdatePetHook(options: { }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts b/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts index c9600a116..f3046728f 100644 --- a/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { UpdatePetWithFormMutationResponse, UpdatePetWithFormPathParams, @@ -30,6 +31,7 @@ export function useUpdatePetWithFormHook(petId: UpdatePetWithFormPathParams['pet client?: UpdatePetWithForm['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useUpdatePetWithFormHook') return useMutation({ mutationFn: async () => { const res = await client({ @@ -40,6 +42,14 @@ export function useUpdatePetWithFormHook(petId: UpdatePetWithFormPathParams['pet }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts b/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts index 17523d215..6d8de8674 100644 --- a/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserPathParams } from '../models/UpdateUser' import type { UseMutationOptions } from '@tanstack/react-query' @@ -26,6 +27,7 @@ export function useUpdateUserHook(username: UpdateUserPathParams['username'], op client?: UpdateUser['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useUpdateUserHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function useUpdateUserHook(username: UpdateUserPathParams['username'], op }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) } diff --git a/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts b/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts index a14013320..9ac955a82 100644 --- a/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts @@ -1,5 +1,6 @@ import client from '@kubb/swagger-client/client' import { useMutation } from '@tanstack/react-query' +import { useInvalidationForMutation } from '../../useInvalidationForMutation' import type { UploadFileMutationRequest, UploadFileMutationResponse, UploadFilePathParams, UploadFileQueryParams } from '../models/UploadFile' import type { UseMutationOptions } from '@tanstack/react-query' @@ -25,6 +26,7 @@ export function useUploadFileHook(petId: UploadFilePathParams['petId'], params?: client?: UploadFile['client']['parameters'] } = {}) { const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + const invalidationOnSuccess = useInvalidationForMutation('useUploadFileHook') return useMutation({ mutationFn: async (data) => { const res = await client({ @@ -36,6 +38,14 @@ export function useUploadFileHook(petId: UploadFilePathParams['petId'], params?: }) return res.data }, + onSuccess: (...args) => { + if (invalidationOnSuccess) { + invalidationOnSuccess(...args) + } + if (mutationOptions?.onSuccess) { + mutationOptions.onSuccess(...args) + } + }, ...mutationOptions, }) }