/** * Commit history — each commit snapshots a tree root for a 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 { databaseGraphCommitKeys } from '../query-keys'; import { databaseGraphCommitMutationKeys } from '../mutation-keys'; import type { DatabaseGraphCommitSelect, DatabaseGraphCommitWithRelations, DatabaseGraphCommitPatch, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { DatabaseGraphCommitSelect, DatabaseGraphCommitWithRelations, DatabaseGraphCommitPatch, } from '../../orm/input-types'; /** * Commit history — each commit snapshots a tree root for a store * * @example * ```tsx * const { mutate, isPending } = useUpdateDatabaseGraphCommitMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', databaseGraphCommitPatch: { name: 'Updated' } }); * ``` */ export function useUpdateDatabaseGraphCommitMutation( params: { selection: { fields: S & DatabaseGraphCommitSelect; } & HookStrictSelect, DatabaseGraphCommitSelect>; } & Omit< UseMutationOptions< { updateDatabaseGraphCommit: { databaseGraphCommit: InferSelectResult; }; }, Error, { id: string; databaseId: string; databaseGraphCommitPatch: DatabaseGraphCommitPatch; } >, 'mutationFn' > ): UseMutationResult< { updateDatabaseGraphCommit: { databaseGraphCommit: InferSelectResult; }; }, Error, { id: string; databaseId: string; databaseGraphCommitPatch: DatabaseGraphCommitPatch; } >; export function useUpdateDatabaseGraphCommitMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; databaseId: string; databaseGraphCommitPatch: DatabaseGraphCommitPatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: databaseGraphCommitMutationKeys.all, mutationFn: ({ id, databaseId, databaseGraphCommitPatch, }: { id: string; databaseId: string; databaseGraphCommitPatch: DatabaseGraphCommitPatch; }) => getClient() .databaseGraphCommit.update({ where: { id, databaseId, }, data: databaseGraphCommitPatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: databaseGraphCommitKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: databaseGraphCommitKeys.lists(), }); }, ...mutationOptions, }); }