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