/** * Delete mutation hook for Table * @generated by @constructive-io/graphql-codegen * DO NOT EDIT - changes will be overwritten */ import { useMutation, useQueryClient } from '@tanstack/react-query'; import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; import { getClient } from '../client'; import { buildSelectionArgs } from '../selection'; import type { SelectionConfig } from '../selection'; import { tableKeys } from '../query-keys'; import { tableMutationKeys } from '../mutation-keys'; import type { TableSelect, TableWithRelations } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { TableSelect, TableWithRelations } from '../../orm/input-types'; /** * Mutation hook for deleting a Table with typed selection * * @example * ```tsx * const { mutate, isPending } = useDeleteTableMutation({ * selection: { fields: { id: true } }, * }); * * mutate({ id: 'value-to-delete' }); * ``` */ export function useDeleteTableMutation( params: { selection: { fields: S & TableSelect; } & HookStrictSelect, TableSelect>; } & Omit< UseMutationOptions< { deleteTable: { table: InferSelectResult; }; }, Error, { id: string; } >, 'mutationFn' > ): UseMutationResult< { deleteTable: { table: InferSelectResult; }; }, Error, { id: string; } >; export function useDeleteTableMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: tableMutationKeys.all, mutationFn: ({ id }: { id: string }) => getClient() .table.delete({ where: { id, }, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.removeQueries({ queryKey: tableKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: tableKeys.lists(), }); }, ...mutationOptions, }); }