Skip to content

index.Function.or

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

Function: or()

function or(...rules): CheckableRule;

Defined in: packages/graphql-casl/src/combinators.ts:245

Passes when any operand passes.

Parameters

rules

...Rule[]

The operands; each must be checkable.

Returns

CheckableRule

A checkable rule.

Remarks

Operands are evaluated in parallel; when all of them fail the last operand's error is thrown, on the reasoning that the last branch is the most specific fallback and so the most useful thing to tell the caller.

An operand that throws counts as a failed operand rather than failing the whole rule, so a passing branch still carries the field. This matters for the common shape or(isRoot, hasRole('ADMIN')), where hasRole reads ctx.user and throws for a caller that has none: the broken branch loses, isRoot wins. If no operand passes and one of them threw, that error is rethrown unchanged in preference to any denial — a rule that broke is an outage to report, not an access decision. and, chain and not stay strict, where a throw fails the rule immediately.

Use race to stop at the first operand that passes instead of always evaluating all of them.

Example

Query: { invoice: or(isOwner, isAccountant) }

API Reference

Clone this wiki locally