Skip to content

scoping.Function.scopeArgs

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

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.

Type Parameters

TSubjectMap

TSubjectMap extends Record<string, object>

The subject map, e.g. SubjectMap<Resolvers, ResolversTypes>.

K

K extends string

TFilter

TFilter

The dialect's filter type.

Parameters

requireCan

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.

action

Action

The action to scope for, e.g. Actions.read.

subject

K

The subject name whose rows are being filtered, e.g. 'Note'.

options

ScopeOptions<TFilter>

The dialect and where to put the filter. See ScopeOptions.

Returns

Rule

A rule; not checkable.

Remarks

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.

Example

import { scopeArgs } from '@vantreeseba/graphql-casl/scoping';

const permissions = {
  Query: {
    notes: scopeArgs(canUser, Actions.read, 'Note', { adapter: drizzleAdapter }),
  },
};

API Reference

Clone this wiki locally