Skip to content

scoping

github-actions[bot] edited this page Oct 14, 2026 · 3 revisions

scoping

Argument scoping — the optional entry point, @vantreeseba/graphql-casl/scoping.

Remarks

The rest of this library is a gate: a rule decides whether a field may be resolved. That is the wrong shape for a generated CRUD field. notes(where:) should not be denied outright because one row is off-limits — it should return the rows the caller may read, and generated resolvers give you no seam to call accessibleBy in.

scopeArgs closes that gap from the outside: it folds the caller's ability into a filter and rewrites the field's arguments before the resolver runs, ANDing the scope onto whatever filter the client sent. The resolver is untouched; it simply receives a narrower where.

Three things to be clear-eyed about before using it:

  1. A scoped field returns fewer rows, not an error. That is the point, but it means a caller cannot tell "no such row" from "not yours".
  2. Injected arguments bypass GraphQL's input coercion. A rule runs downstream of validation, so a filter in the wrong dialect is not rejected — it reaches the data layer as written, where it may be ignored and quietly widen access. Match the adapter to the schema's actual input type, and test it.
  3. It scopes the field you name, not the graph below it. The rewrite reaches the rows that field resolves. A generated relation field — Note.author, User.notes — resolves through its own path and may ignore an injected filter entirely, handing back rows the scope would have excluded while reporting success. Scope each relation field in its own right, put a rule on it, or push the scope into the data layer (row- level security, a per-request scoped client), where nothing can route around it.

Interfaces

Type Aliases

Variables

Functions

API Reference

Clone this wiki locally