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