/** * DO INSTEAD rules for views (e.g., read-only enforcement) * @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 { viewRuleKeys } from '../query-keys'; import { viewRuleMutationKeys } from '../mutation-keys'; import type { ViewRuleSelect, ViewRuleWithRelations } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { ViewRuleSelect, ViewRuleWithRelations } from '../../orm/input-types'; /** * DO INSTEAD rules for views (e.g., read-only enforcement) * * @example * ```tsx * const { mutate, isPending } = useDeleteViewRuleMutation({ * selection: { fields: { id: true } }, * }); * * mutate({ id: 'value-to-delete' }); * ``` */ export function useDeleteViewRuleMutation( params: { selection: { fields: S & ViewRuleSelect; } & HookStrictSelect, ViewRuleSelect>; } & Omit< UseMutationOptions< { deleteViewRule: { viewRule: InferSelectResult; }; }, Error, { id: string; } >, 'mutationFn' > ): UseMutationResult< { deleteViewRule: { viewRule: InferSelectResult; }; }, Error, { id: string; } >; export function useDeleteViewRuleMutation( 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: viewRuleMutationKeys.all, mutationFn: ({ id }: { id: string }) => getClient() .viewRule.delete({ where: { id, }, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.removeQueries({ queryKey: viewRuleKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: viewRuleKeys.lists(), }); }, ...mutationOptions, }); }