/** * Records of individual capability grants and revocations for members via bitmask * @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 { appGrantKeys } from '../query-keys'; import { appGrantMutationKeys } from '../mutation-keys'; import type { AppGrantSelect, AppGrantWithRelations, AppGrantPatch } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { AppGrantSelect, AppGrantWithRelations, AppGrantPatch } from '../../orm/input-types'; /** * Records of individual capability grants and revocations for members via bitmask * * @example * ```tsx * const { mutate, isPending } = useUpdateAppGrantMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ id: 'value-here', appGrantPatch: { name: 'Updated' } }); * ``` */ export function useUpdateAppGrantMutation( params: { selection: { fields: S & AppGrantSelect; } & HookStrictSelect, AppGrantSelect>; } & Omit< UseMutationOptions< { updateAppGrant: { appGrant: InferSelectResult; }; }, Error, { id: string; appGrantPatch: AppGrantPatch; } >, 'mutationFn' > ): UseMutationResult< { updateAppGrant: { appGrant: InferSelectResult; }; }, Error, { id: string; appGrantPatch: AppGrantPatch; } >; export function useUpdateAppGrantMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions< any, Error, { id: string; appGrantPatch: AppGrantPatch; } >, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: appGrantMutationKeys.all, mutationFn: ({ id, appGrantPatch }: { id: string; appGrantPatch: AppGrantPatch }) => getClient() .appGrant.update({ where: { id, }, data: appGrantPatch, select: args.select, }) .unwrap(), onSuccess: (_, variables) => { queryClient.invalidateQueries({ queryKey: appGrantKeys.detail(variables.id), }); queryClient.invalidateQueries({ queryKey: appGrantKeys.lists(), }); }, ...mutationOptions, }); }