/** * Routes binding a domain hostname and path to a typed catalog target * @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 { routeKeys } from '../query-keys'; import { routeMutationKeys } from '../mutation-keys'; import type { RouteSelect, RouteWithRelations, CreateRouteInput } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { RouteSelect, RouteWithRelations, CreateRouteInput } from '../../orm/input-types'; /** * Routes binding a domain hostname and path to a typed catalog target * * @example * ```tsx * const { mutate, isPending } = useCreateRouteMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreateRouteMutation( params: { selection: { fields: S & RouteSelect; } & HookStrictSelect, RouteSelect>; } & Omit< UseMutationOptions< { createRoute: { route: InferSelectResult; }; }, Error, CreateRouteInput['route'] >, 'mutationFn' > ): UseMutationResult< { createRoute: { route: InferSelectResult; }; }, Error, CreateRouteInput['route'] >; export function useCreateRouteMutation( params: { selection: SelectionConfig; } & Omit, 'mutationFn'> ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: routeMutationKeys.create(), mutationFn: (data: CreateRouteInput['route']) => getClient() .route.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: routeKeys.lists(), }); }, ...mutationOptions, }); }