/** * RLS module runtime configuration; typed references to the authenticate/current_role function plumbing * @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 { rlsSettingKeys } from '../query-keys'; import { rlsSettingMutationKeys } from '../mutation-keys'; import type { RlsSettingSelect, RlsSettingWithRelations, RlsSettingPatch, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { RlsSettingSelect, RlsSettingWithRelations, RlsSettingPatch, } from '../../orm/input-types'; /** * RLS module runtime configuration; typed references to the authenticate/current_role function plumbing * * @example * ```tsx * const { mutate, isPending } = useUpdateRlsSettingMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', rlsSettingPatch: { name: 'Updated' } }); * ``` */ export function useUpdateRlsSettingMutation( params: { selection: { fields: S & RlsSettingSelect; } & HookStrictSelect, RlsSettingSelect>; } & Omit< UseMutationOptions< { updateRlsSetting: { rlsSetting: InferSelectResult; }; }, Error, { id: string; rlsSettingPatch: RlsSettingPatch; } >, 'mutationFn' > ): UseMutationResult< { updateRlsSetting: { rlsSetting: InferSelectResult; }; }, Error, { id: string; rlsSettingPatch: RlsSettingPatch; } >; export function useUpdateRlsSettingMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; rlsSettingPatch: RlsSettingPatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: rlsSettingMutationKeys.all, mutationFn: ({ id, rlsSettingPatch }: { id: string; rlsSettingPatch: RlsSettingPatch }) => getClient() .rlsSetting.update({ where: { id, }, data: rlsSettingPatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: rlsSettingKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: rlsSettingKeys.lists(), }); }, ...mutationOptions, }); }