/** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * @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 { databaseGraphObjectKeys } from '../query-keys'; import { databaseGraphObjectMutationKeys } from '../mutation-keys'; import type { DatabaseGraphObjectSelect, DatabaseGraphObjectWithRelations, CreateDatabaseGraphObjectInput, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { DatabaseGraphObjectSelect, DatabaseGraphObjectWithRelations, CreateDatabaseGraphObjectInput, } from '../../orm/input-types'; /** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * * @example * ```tsx * const { mutate, isPending } = useCreateDatabaseGraphObjectMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreateDatabaseGraphObjectMutation( params: { selection: { fields: S & DatabaseGraphObjectSelect; } & HookStrictSelect, DatabaseGraphObjectSelect>; } & Omit< UseMutationOptions< { createDatabaseGraphObject: { databaseGraphObject: InferSelectResult; }; }, Error, CreateDatabaseGraphObjectInput['databaseGraphObject'] >, 'mutationFn' > ): UseMutationResult< { createDatabaseGraphObject: { databaseGraphObject: InferSelectResult; }; }, Error, CreateDatabaseGraphObjectInput['databaseGraphObject'] >; export function useCreateDatabaseGraphObjectMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: databaseGraphObjectMutationKeys.create(), mutationFn: (data: CreateDatabaseGraphObjectInput['databaseGraphObject']) => getClient() .databaseGraphObject.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: databaseGraphObjectKeys.lists(), }); }, ...mutationOptions, }); }