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