/** * Named stores — one per version-controlled tree (e.g. one graph, one definition set) * @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 { functionGraphStoreKeys } from '../query-keys'; import { functionGraphStoreMutationKeys } from '../mutation-keys'; import type { FunctionGraphStoreSelect, FunctionGraphStoreWithRelations, FunctionGraphStorePatch, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { FunctionGraphStoreSelect, FunctionGraphStoreWithRelations, FunctionGraphStorePatch, } from '../../orm/input-types'; /** * Named stores — one per version-controlled tree (e.g. one graph, one definition set) * * @example * ```tsx * const { mutate, isPending } = useUpdateFunctionGraphStoreMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', functionGraphStorePatch: { name: 'Updated' } }); * ``` */ export function useUpdateFunctionGraphStoreMutation( params: { selection: { fields: S & FunctionGraphStoreSelect; } & HookStrictSelect, FunctionGraphStoreSelect>; } & Omit< UseMutationOptions< { updateFunctionGraphStore: { functionGraphStore: InferSelectResult; }; }, Error, { id: string; functionGraphStorePatch: FunctionGraphStorePatch; } >, 'mutationFn' > ): UseMutationResult< { updateFunctionGraphStore: { functionGraphStore: InferSelectResult; }; }, Error, { id: string; functionGraphStorePatch: FunctionGraphStorePatch; } >; export function useUpdateFunctionGraphStoreMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; functionGraphStorePatch: FunctionGraphStorePatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: functionGraphStoreMutationKeys.all, mutationFn: ({ id, functionGraphStorePatch, }: { id: string; functionGraphStorePatch: FunctionGraphStorePatch; }) => getClient() .functionGraphStore.update({ where: { id, }, data: functionGraphStorePatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: functionGraphStoreKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: functionGraphStoreKeys.lists(), }); }, ...mutationOptions, }); }