Skip to content

index.Function.granted

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

Function: granted()

function granted(scope): CheckableRule;

Defined in: packages/graphql-casl/src/grants.ts:197

A CheckableRule that passes when the field's parent was granted scope earlier in this request, and denies with Forbidden otherwise.

Parameters

scope

string

The scope name to look for.

Returns

CheckableRule

A checkable, synchronous rule.

Remarks

The check is synchronous — a WeakMap lookup — so a field it guards resolves without a promise, and it needs no cache: it is already cheaper than a cache hit. Put it first in a race so the fallback check only runs for rows that arrived some other way:

Post: race(granted('post'), canUser.fields(Actions.read, Subject.Post)),

On its own it is deny-by-default: a Post that no granting field returned — one reached through a field that does not grant, or a root field's parent, which is no object at all — is denied. That is what makes it a scope rather than a bypass. Use race / or when the type is also reachable by paths that should authorize it themselves.

API Reference

Clone this wiki locally