/** * Audit trail of domain lifecycle events * @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 { domainEventKeys } from '../query-keys'; import { domainEventMutationKeys } from '../mutation-keys'; import type { DomainEventSelect, DomainEventWithRelations } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { DomainEventSelect, DomainEventWithRelations } from '../../orm/input-types'; /** * Audit trail of domain lifecycle events * * @example * ```tsx * const { mutate, isPending } = useDeleteDomainEventMutation({ * selection: { fields: { id: true } }, * }); * * mutate({ id: 'value-to-delete' }); * ``` */ export function useDeleteDomainEventMutation( params: { selection: { fields: S & DomainEventSelect; } & HookStrictSelect, DomainEventSelect>; } & Omit< UseMutationOptions< { deleteDomainEvent: { domainEvent: InferSelectResult; }; }, Error, { id: string; } >, 'mutationFn' > ): UseMutationResult< { deleteDomainEvent: { domainEvent: InferSelectResult; }; }, Error, { id: string; } >; export function useDeleteDomainEventMutation( 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: domainEventMutationKeys.all, mutationFn: ({ id }: { id: string }) => getClient() .domainEvent.delete({ where: { id, }, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.removeQueries({ queryKey: domainEventKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: domainEventKeys.lists(), }); }, ...mutationOptions, }); }