/** * Junction table linking views to their joined tables for referential integrity * @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 { viewTableKeys } from '../query-keys'; import { viewTableMutationKeys } from '../mutation-keys'; import type { ViewTableSelect, ViewTableWithRelations, CreateViewTableInput, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { ViewTableSelect, ViewTableWithRelations, CreateViewTableInput, } from '../../orm/input-types'; /** * Junction table linking views to their joined tables for referential integrity * * @example * ```tsx * const { mutate, isPending } = useCreateViewTableMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreateViewTableMutation( params: { selection: { fields: S & ViewTableSelect; } & HookStrictSelect, ViewTableSelect>; } & Omit< UseMutationOptions< { createViewTable: { viewTable: InferSelectResult; }; }, Error, CreateViewTableInput['viewTable'] >, 'mutationFn' > ): UseMutationResult< { createViewTable: { viewTable: InferSelectResult; }; }, Error, CreateViewTableInput['viewTable'] >; export function useCreateViewTableMutation( params: { selection: SelectionConfig; } & Omit, 'mutationFn'> ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: viewTableMutationKeys.create(), mutationFn: (data: CreateViewTableInput['viewTable']) => getClient() .viewTable.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: viewTableKeys.lists(), }); }, ...mutationOptions, }); }