Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Mar 9, 2024
1 parent 1e9b121 commit cf95da4
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/react-query-v5/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -60,6 +61,7 @@ export const config = {
}],
templates: {
operations: operations.templates,
mutation: mutation.templates,
},
}),
],
Expand Down
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useAddPetHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<AddPet['data'], AddPet['error'], AddPet['request']>({
Expand All @@ -36,6 +38,14 @@ export function useAddPetHook(options: {
})
return res.data
},
onSuccess: (...args) => {
if (invalidationOnSuccess) {
invalidationOnSuccess(...args)
}
if (mutationOptions?.onSuccess) {
mutationOptions.onSuccess(...args)
}
},
...mutationOptions,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<CreateUser['data'], CreateUser['error'], CreateUser['request']>({
Expand All @@ -36,6 +38,14 @@ export function useCreateUserHook(options: {
})
return res.data
},
onSuccess: (...args) => {
if (invalidationOnSuccess) {
invalidationOnSuccess(...args)
}
if (mutationOptions?.onSuccess) {
mutationOptions.onSuccess(...args)
}
},
...mutationOptions,
})
}
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<CreateUsersWithListInput['data'], CreateUsersWithListInput['error'], CreateUsersWithListInput['request']>({
Expand All @@ -36,6 +38,14 @@ export function useCreateUsersWithListInputHook(options: {
})
return res.data
},
onSuccess: (...args) => {
if (invalidationOnSuccess) {
invalidationOnSuccess(...args)
}
if (mutationOptions?.onSuccess) {
mutationOptions.onSuccess(...args)
}
},
...mutationOptions,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<DeleteOrder['data'], DeleteOrder['error'], void>({
Expand All @@ -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,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<DeletePet['data'], DeletePet['error'], void>({
Expand All @@ -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,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<DeleteUser['data'], DeleteUser['error'], void>({
Expand All @@ -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,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<PlaceOrder['data'], PlaceOrder['error'], PlaceOrder['request']>({
Expand All @@ -36,6 +38,14 @@ export function usePlaceOrderHook(options: {
})
return res.data
},
onSuccess: (...args) => {
if (invalidationOnSuccess) {
invalidationOnSuccess(...args)
}
if (mutationOptions?.onSuccess) {
mutationOptions.onSuccess(...args)
}
},
...mutationOptions,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<PlaceOrderPatch['data'], PlaceOrderPatch['error'], PlaceOrderPatch['request']>({
Expand All @@ -36,6 +38,14 @@ export function usePlaceOrderPatchHook(options: {
})
return res.data
},
onSuccess: (...args) => {
if (invalidationOnSuccess) {
invalidationOnSuccess(...args)
}
if (mutationOptions?.onSuccess) {
mutationOptions.onSuccess(...args)
}
},
...mutationOptions,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<UpdatePet['data'], UpdatePet['error'], UpdatePet['request']>({
Expand All @@ -36,6 +38,14 @@ export function useUpdatePetHook(options: {
})
return res.data
},
onSuccess: (...args) => {
if (invalidationOnSuccess) {
invalidationOnSuccess(...args)
}
if (mutationOptions?.onSuccess) {
mutationOptions.onSuccess(...args)
}
},
...mutationOptions,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<UpdatePetWithForm['data'], UpdatePetWithForm['error'], void>({
Expand All @@ -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,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<UpdateUser['data'], UpdateUser['error'], UpdateUser['request']>({
Expand All @@ -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,
})
}
10 changes: 10 additions & 0 deletions examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<UploadFile['data'], UploadFile['error'], UploadFile['request']>({
Expand All @@ -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,
})
}

0 comments on commit cf95da4

Please sign in to comment.