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