/** * Create mutation hook for Index * @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 { indexKeys } from '../query-keys'; import { indexMutationKeys } from '../mutation-keys'; import type { IndexSelect, IndexWithRelations, CreateIndexInput } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { IndexSelect, IndexWithRelations, CreateIndexInput } from '../../orm/input-types'; /** * Mutation hook for creating a Index * * @example * ```tsx * const { mutate, isPending } = useCreateIndexMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreateIndexMutation( params: { selection: { fields: S & IndexSelect; } & HookStrictSelect, IndexSelect>; } & Omit< UseMutationOptions< { createIndex: { index: InferSelectResult; }; }, Error, CreateIndexInput['index'] >, 'mutationFn' > ): UseMutationResult< { createIndex: { index: InferSelectResult; }; }, Error, CreateIndexInput['index'] >; export function useCreateIndexMutation( params: { selection: SelectionConfig; } & Omit, 'mutationFn'> ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: indexMutationKeys.create(), mutationFn: (data: CreateIndexInput['index']) => getClient() .index.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: indexKeys.lists(), }); }, ...mutationOptions, }); }