/** * Named stores — one per version-controlled tree (e.g. one graph, one definition set) * @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 { functionGraphStoreKeys } from '../query-keys'; import { functionGraphStoreMutationKeys } from '../mutation-keys'; import type { FunctionGraphStoreSelect, FunctionGraphStoreWithRelations, CreateFunctionGraphStoreInput, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { FunctionGraphStoreSelect, FunctionGraphStoreWithRelations, CreateFunctionGraphStoreInput, } from '../../orm/input-types'; /** * Named stores — one per version-controlled tree (e.g. one graph, one definition set) * * @example * ```tsx * const { mutate, isPending } = useCreateFunctionGraphStoreMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreateFunctionGraphStoreMutation( params: { selection: { fields: S & FunctionGraphStoreSelect; } & HookStrictSelect, FunctionGraphStoreSelect>; } & Omit< UseMutationOptions< { createFunctionGraphStore: { functionGraphStore: InferSelectResult; }; }, Error, CreateFunctionGraphStoreInput['functionGraphStore'] >, 'mutationFn' > ): UseMutationResult< { createFunctionGraphStore: { functionGraphStore: InferSelectResult; }; }, Error, CreateFunctionGraphStoreInput['functionGraphStore'] >; export function useCreateFunctionGraphStoreMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: functionGraphStoreMutationKeys.create(), mutationFn: (data: CreateFunctionGraphStoreInput['functionGraphStore']) => getClient() .functionGraphStore.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: functionGraphStoreKeys.lists(), }); }, ...mutationOptions, }); }