/** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * @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 { databaseGraphObjectKeys } from '../query-keys'; import { databaseGraphObjectMutationKeys } from '../mutation-keys'; import type { DatabaseGraphObjectSelect, DatabaseGraphObjectWithRelations, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { DatabaseGraphObjectSelect, DatabaseGraphObjectWithRelations, } from '../../orm/input-types'; /** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * * @example * ```tsx * const { mutate, isPending } = useDeleteDatabaseGraphObjectMutation({ * selection: { fields: { id: true } }, * }); * * mutate({ id: 'value-to-delete' }); * ``` */ export function useDeleteDatabaseGraphObjectMutation( params: { selection: { fields: S & DatabaseGraphObjectSelect; } & HookStrictSelect, DatabaseGraphObjectSelect>; } & Omit< UseMutationOptions< { deleteDatabaseGraphObject: { databaseGraphObject: InferSelectResult; }; }, Error, { id: string; databaseId: string; } >, 'mutationFn' > ): UseMutationResult< { deleteDatabaseGraphObject: { databaseGraphObject: InferSelectResult; }; }, Error, { id: string; databaseId: string; } >; export function useDeleteDatabaseGraphObjectMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; databaseId: string; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: databaseGraphObjectMutationKeys.all, mutationFn: ({ id, databaseId }: { id: string; databaseId: string }) => getClient() .databaseGraphObject.delete({ where: { id, databaseId, }, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.removeQueries({ queryKey: databaseGraphObjectKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: databaseGraphObjectKeys.lists(), }); }, ...mutationOptions, }); }