Skip to content

index.Variable.UnconditionedSubjectMode

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

Variable: UnconditionedSubjectMode

const UnconditionedSubjectMode: {
  Allow: "allow";
  Throw: "throw";
  Warn: "warn";
};

Defined in: packages/graphql-casl/src/createCan.ts:39

What createCan does when a bare-subject check is made against a subject whose only matching rules carry conditions.

Type Declaration

Allow

readonly Allow: "allow" = 'allow';

Throw

readonly Throw: "throw" = 'throw';

Warn

readonly Warn: "warn" = 'warn';

Remarks

ability.can('update', 'Note') asks CASL "is updating a Note possible at all?", not "may I update this Note?" — a rule of can('update', 'Note', { userId }) makes the bare check return true for every caller. Omitting getSubjectData there silently discards the conditions, with no type error to catch it.

  • 'warn' (default) — allow the check, but log once per rule. Non-breaking.
  • 'throw' — deny with an explanatory error. Recommended for new projects.
  • 'allow' — say nothing. For deliberate "is this possible at all" gates, e.g. guarding a list field whose rows are filtered inside the resolver.

The object names each mode: onUnconditionedSubject: UnconditionedSubjectMode.Throw.

API Reference

Clone this wiki locally