/** * 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, CreateDatabaseGraphCommitInput, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { DatabaseGraphCommitSelect, DatabaseGraphCommitWithRelations, CreateDatabaseGraphCommitInput, } from '../../orm/input-types'; /** * Commit history — each commit snapshots a tree root for a store * * @example * ```tsx * const { mutate, isPending } = useCreateDatabaseGraphCommitMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreateDatabaseGraphCommitMutation( params: { selection: { fields: S & DatabaseGraphCommitSelect; } & HookStrictSelect, DatabaseGraphCommitSelect>; } & Omit< UseMutationOptions< { createDatabaseGraphCommit: { databaseGraphCommit: InferSelectResult; }; }, Error, CreateDatabaseGraphCommitInput['databaseGraphCommit'] >, 'mutationFn' > ): UseMutationResult< { createDatabaseGraphCommit: { databaseGraphCommit: InferSelectResult; }; }, Error, CreateDatabaseGraphCommitInput['databaseGraphCommit'] >; export function useCreateDatabaseGraphCommitMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: databaseGraphCommitMutationKeys.create(), mutationFn: (data: CreateDatabaseGraphCommitInput['databaseGraphCommit']) => getClient() .databaseGraphCommit.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: databaseGraphCommitKeys.lists(), }); }, ...mutationOptions, }); }