/** * Update mutation hook for ClusterModule * @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 { clusterModuleKeys } from '../query-keys'; import { clusterModuleMutationKeys } from '../mutation-keys'; import type { ClusterModuleSelect, ClusterModuleWithRelations, ClusterModulePatch, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { ClusterModuleSelect, ClusterModuleWithRelations, ClusterModulePatch, } from '../../orm/input-types'; /** * Mutation hook for updating a ClusterModule * * @example * ```tsx * const { mutate, isPending } = useUpdateClusterModuleMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', clusterModulePatch: { name: 'Updated' } }); * ``` */ export function useUpdateClusterModuleMutation( params: { selection: { fields: S & ClusterModuleSelect; } & HookStrictSelect, ClusterModuleSelect>; } & Omit< UseMutationOptions< { updateClusterModule: { clusterModule: InferSelectResult; }; }, Error, { id: string; clusterModulePatch: ClusterModulePatch; } >, 'mutationFn' > ): UseMutationResult< { updateClusterModule: { clusterModule: InferSelectResult; }; }, Error, { id: string; clusterModulePatch: ClusterModulePatch; } >; export function useUpdateClusterModuleMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; clusterModulePatch: ClusterModulePatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: clusterModuleMutationKeys.all, mutationFn: ({ id, clusterModulePatch, }: { id: string; clusterModulePatch: ClusterModulePatch; }) => getClient() .clusterModule.update({ where: { id, }, data: clusterModulePatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: clusterModuleKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: clusterModuleKeys.lists(), }); }, ...mutationOptions, }); }