/** * Database provisioning preset catalog — merkle-versioned head over the infra store * @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 { dbPresetKeys } from '../query-keys'; import { dbPresetMutationKeys } from '../mutation-keys'; import type { DbPresetSelect, DbPresetWithRelations, DbPresetPatch } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { DbPresetSelect, DbPresetWithRelations, DbPresetPatch } from '../../orm/input-types'; /** * Database provisioning preset catalog — merkle-versioned head over the infra store * * @example * ```tsx * const { mutate, isPending } = useUpdateDbPresetMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', dbPresetPatch: { name: 'Updated' } }); * ``` */ export function useUpdateDbPresetMutation( params: { selection: { fields: S & DbPresetSelect; } & HookStrictSelect, DbPresetSelect>; } & Omit< UseMutationOptions< { updateDbPreset: { dbPreset: InferSelectResult; }; }, Error, { id: string; dbPresetPatch: DbPresetPatch; } >, 'mutationFn' > ): UseMutationResult< { updateDbPreset: { dbPreset: InferSelectResult; }; }, Error, { id: string; dbPresetPatch: DbPresetPatch; } >; export function useUpdateDbPresetMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; dbPresetPatch: DbPresetPatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: dbPresetMutationKeys.all, mutationFn: ({ id, dbPresetPatch }: { id: string; dbPresetPatch: DbPresetPatch }) => getClient() .dbPreset.update({ where: { id, }, data: dbPresetPatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: dbPresetKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: dbPresetKeys.lists(), }); }, ...mutationOptions, }); }