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