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