/** * Provisions the principals subsystem: a principals table, a principal_entities junction table, create/delete mutations, and org API key management. Supports both human-owned principals (AuthzDirectOwner, AuthzHumanOnly) and org-owned principals (AuthzEntityMembership with is_admin). Org principal and org API key functions are only generated when an org-scoped memberships_module exists for the database. * @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 { principalAuthModuleKeys } from '../query-keys'; import { principalAuthModuleMutationKeys } from '../mutation-keys'; import type { PrincipalAuthModuleSelect, PrincipalAuthModuleWithRelations, CreatePrincipalAuthModuleInput, } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { PrincipalAuthModuleSelect, PrincipalAuthModuleWithRelations, CreatePrincipalAuthModuleInput, } from '../../orm/input-types'; /** * Provisions the principals subsystem: a principals table, a principal_entities junction table, create/delete mutations, and org API key management. Supports both human-owned principals (AuthzDirectOwner, AuthzHumanOnly) and org-owned principals (AuthzEntityMembership with is_admin). Org principal and org API key functions are only generated when an org-scoped memberships_module exists for the database. * * @example * ```tsx * const { mutate, isPending } = useCreatePrincipalAuthModuleMutation({ * selection: { fields: { id: true, name: true } }, * }); * * mutate({ name: 'New item' }); * ``` */ export function useCreatePrincipalAuthModuleMutation( params: { selection: { fields: S & PrincipalAuthModuleSelect; } & HookStrictSelect, PrincipalAuthModuleSelect>; } & Omit< UseMutationOptions< { createPrincipalAuthModule: { principalAuthModule: InferSelectResult; }; }, Error, CreatePrincipalAuthModuleInput['principalAuthModule'] >, 'mutationFn' > ): UseMutationResult< { createPrincipalAuthModule: { principalAuthModule: InferSelectResult; }; }, Error, CreatePrincipalAuthModuleInput['principalAuthModule'] >; export function useCreatePrincipalAuthModuleMutation( params: { selection: SelectionConfig; } & Omit< UseMutationOptions, 'mutationFn' > ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...mutationOptions } = params ?? {}; void _selection; const queryClient = useQueryClient(); return useMutation({ mutationKey: principalAuthModuleMutationKeys.create(), mutationFn: (data: CreatePrincipalAuthModuleInput['principalAuthModule']) => getClient() .principalAuthModule.create({ data, select: args.select, }) .unwrap(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: principalAuthModuleKeys.lists(), }); }, ...mutationOptions, }); }