Skip to content

index.Function.buildGraphQLAbility

github-actions[bot] edited this page Nov 30, 2026 · 26 revisions

Function: buildGraphQLAbility()

function buildGraphQLAbility<TSubjectMap>(rules, options?): GraphQLAbility<TSubjectMap>;

Defined in: packages/graphql-casl/src/graphqlAbility.ts:125

Reconstructs a GraphQLAbility from previously-stored GraphQLRules — the path for loading rules persisted in a database (and caching them) at app start. Applies __typename detection (the mongo conditions matcher is built in).

Type Parameters

TSubjectMap

TSubjectMap extends Record<string, object>

The subject map, e.g. SubjectMap<Resolvers, ResolversTypes>.

Parameters

rules

GraphQLRule<TSubjectMap>[]

The stored rules.

options?

Partial<AbilityOptionsOf<GraphQLAbility<TSubjectMap>>>

Extra CASL ability options to override or extend the defaults.

Returns

GraphQLAbility<TSubjectMap>

The ability.

Example

const rules: GraphQLRule<AppSubjectMap>[] = await db.loadPermissionRules();
const ability = buildGraphQLAbility<AppSubjectMap>(rules);

API Reference

Clone this wiki locally