Skip to content

index.Function.rule

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

Function: rule()

function rule(check, options?): CheckableRule;

Defined in: packages/graphql-casl/src/rules.ts:461

Wraps a Check into a CheckableRule — a rule usable directly in a PermissionsMap and as an operand of the combinators.

Parameters

check

Check

The predicate. See RuleResult for what it may return.

options?

RuleOptions

See RuleOptions.

Returns

CheckableRule

A checkable rule.

Remarks

The check runs before the resolver; a denial rejects and the resolver never runs. An error raised inside the check propagates unchanged rather than being converted into a denial, so a broken check is not silently mistaken for a legitimate Forbidden.

Example

const isSelf = rule(
  (parent, args: { id: string }, ctx) =>
    args.id === ctx.userId || 'You may only read your own profile',
  { name: 'isSelf' },
);

API Reference

Clone this wiki locally