Repository navigation
scoping.Function.scopeArgs
function scopeArgs<TSubjectMap, K, TFilter>(
requireCan,
action,
subject,
options): Rule;Defined in: packages/graphql-casl/src/scoping.ts:133
A rule that narrows a field's filter argument to the rows the caller may
action, instead of allowing or denying the field outright.
TSubjectMap extends Record<string, object>
The subject map, e.g. SubjectMap<Resolvers, ResolversTypes>.
K extends string
TFilter
The dialect's filter type.
Scopable<TSubjectMap>
The requireCan returned by createCan. Its
authentication check and per-request ability memo are reused, so a scoped
field costs no extra ability build.
The action to scope for, e.g. Actions.read.
K
The subject name whose rows are being filtered, e.g. 'Note'.
ScopeOptions<TFilter>
The dialect and where to put the filter. See ScopeOptions.
A rule; not checkable.
It is a plain Rule, not a CheckableRule: it decides by rewriting
arguments and calling the resolver, so it cannot be an operand of and /
or / not / chain / race. Use wrap to put a gate in front of it —
wrap(isNotBanned, scopeArgs(...)) — or to stack it with onResult. Pair it
with fallbackRule too: a scoped field is not an authenticated-only field,
and scoping alone says nothing about the fields around it.
import { scopeArgs } from '@vantreeseba/graphql-casl/scoping';
const permissions = {
Query: {
notes: scopeArgs(canUser, Actions.read, 'Note', { adapter: drizzleAdapter }),
},
};