/** * Computers enrolled for remote control, one row per database enrollment * @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 { machineKeys } from '../query-keys'; import { machineMutationKeys } from '../mutation-keys'; import type { MachineSelect, MachineWithRelations } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { MachineSelect, MachineWithRelations } from '../../orm/input-types'; /** * Computers enrolled for remote control, one row per database enrollment * * @example * ```tsx * const { mutate, isPending } = useDeleteMachineMutation({ * selection: { fields: { id: true } }, * }); * * mutate({ id: 'value-to-delete' }); * ``` */ export function useDeleteMachineMutation( params: { selection: { fields: S & MachineSelect; } & HookStrictSelect, MachineSelect>; } & Omit< UseMutationOptions< { deleteMachine: { machine: InferSelectResult; }; }, Error, { id: string; } >, 'mutationFn' > ): UseMutationResult< { deleteMachine: { machine: InferSelectResult; }; }, Error, { id: string; } >; export function useDeleteMachineMutation( 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: machineMutationKeys.all, mutationFn: ({ id }: { id: string }) => getClient() .machine.delete({ where: { id, }, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.removeQueries({ queryKey: machineKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: machineKeys.lists(), }); }, ...mutationOptions, }); }