# @vantreeseba/graphql-casl > GraphQL middleware plugin for defining CASL permission rules on resolvers, with optional argument scoping and an envelop/Yoga integration. Agent-facing docs for @vantreeseba/graphql-casl: one task or concept per page, then what each package.json "exports" entry exports. Generated from _agents/docs/ and the doc comments in src/ by @cubicecho/agent-docs; edit those, not this file. Peer dependencies: `@casl/ability` >=6, `@envelop/core` >=5 (optional), `@envelop/on-resolve` >=7 (optional), `graphql` >=16, `graphql-middleware` >=6. ## Docs - [Install and generate the types](_agents/docs/01-install.md): Install the package with its peers, and generate the `Resolvers` and `ResolversTypes` that every type helper is keyed off, or start without them. - [Quick start](_agents/docs/02-quick-start.md): The whole shape in one file: an ability per request, `createCan` bound to the context, a permissions map, and `applyPermissions` over an executable schema. - [Abilities, subjects and conditions](_agents/docs/abilities.md): An ability says what one caller may do; this page covers building one typed against your schema, how objects are recognised as subjects, what conditions may hold, and storing rules. - [Apply the map to a schema](_agents/docs/apply-permissions.md): What `applyPermissions` validates and guards, the options that change it, and what a client sees when a field is denied. - [Common mistakes](_agents/docs/common-mistakes.md): Mistakes that type-check and run, with what happens and the fix. The first section lists the ones that leave data open. - [Entry points](_agents/docs/entry-points.md): When to import `/scoping`, `/envelop` or `/apollo` beside the main entry, with the minimal wiring for each. - [Topic guides](_agents/docs/guides.md): One line per advanced topic with the exports it uses and its main constraint, and a link to the full guide on GitHub. - [The permissions map](_agents/docs/permissions-map.md): How to bind rules to your context with `createCan`, write a `PermissionsMap`, pick the right kind of rule for each field, and which entry wins when several match. ## Exports: @vantreeseba/graphql-casl graphql-casl — generic CASL permissions middleware for GraphQL resolvers. - `AbilityLike` (type): Minimal structural type for anything with a CASL-style `can` method — what the rule layer needs to check an action against a subject. - `Action` (type): The CASL action verbs supported by this middleware. - `Actions`: Const object holding every Action value — use instead of raw strings in `can`/`cannot` calls and rule definitions to get autocomplete and catch typos at compile time. - `isAction`: Whether a value is one of the Action verbs. - `AccessibleFilter` (type): The default filter shape: one subject's CASL conditions, combined with mongo's boolean operators. - `accessibleBy`: The filter matching every row of `subject` the ability permits `action` on, or `null` when it permits none. - `ApplyPermissionsOptions` (type): Options for applyPermissions. - `PermissionResolver` (type): Looks up the rule guarding one field, already wrapped with the error-control and masking options. - `applyPermissions`: Applies a PermissionsMap to an executable schema via `graphql-middleware`. - `resolvePermissions`: Resolves a PermissionsMap against a schema into a per-field lookup, without applying it to anything. - `and`: Passes when **every** operand passes. - `chain`: Sequential and: evaluates operands in order and stops at the first failure, throwing its error. - `not`: Inverts a rule: passes when the operand denies, denies when it passes. - `or`: Passes when **any** operand passes. - `race`: Sequential or: evaluates operands in order and stops at the first one that passes. - `wrap`: Composes rules as nested middleware: each one receives the next as its `resolve`, and the last receives the field's real resolver. - `AdapterCore` (type): The combinators every dialect must supply. - `FilterAdapter` (type): Builds the filter dialect `accessibleBy` and argument scoping produce: either a SkeletonAdapter or a LeafAdapter. - `LeafAdapter` (type): A dialect that controls the leaves as well as the skeleton. - `LeafCondition` (type): One comparison, flattened out of a condition object. - `LeafOperator` (type): A mongo-query comparison operator, as CASL conditions use them. - `SkeletonAdapter` (type): A dialect that controls the boolean skeleton and passes conditions through verbatim. - `BuildSubject` (type): A subject tagger, typically `createTyped`'s `typed`: turns a subject name plus field values into a `__typename`-tagged instance CASL can classify. - `CanRuleOptions` (type): Options for one rule built by a RequireCan builder. - `CreateCanOptions` (type): Options for createCan. - `RequireCan` (type): The rule builder returned by createCan when a `buildSubject` tagger is provided. - `RequireCanBare` (type): The rule builder returned by createCan when no `buildSubject` tagger is provided. - `RequireCanFields` (type): Builds a single rule that guards **every field of a type**, deciding each one from CASL's field-level permissions rather than from a hand-written entry. - `RequireCanOnResult` (type): Builds a rule that runs the resolver first and authorizes what it returned. - `createCan`: Factory that returns a `requireCan(action, subject, getSubjectData?)` rule builder bound to a specific ability resolver and subject map. - `UnconditionedSubjectMode`: What createCan does when a bare-subject check is made against a subject whose only matching rules carry conditions. - `AUTHORIZATION_ERRORS_EXTENSION`: The response extension reportDenials fills under `report: 'extensions'` — again Apollo Router's key, holding the same error objects it would otherwise put in `errors`. - `DenialMode`: What a denied field does — see ApplyPermissionsOptions.onDeny. - `DenialReport`: Where a filtered denial is reported — see ApplyPermissionsOptions.report. - `reportDenials`: Merges the denials `onDeny: 'filter'` recorded for a request into its execution result — the ones the response could not carry through the denied field itself (see ApplyPermissionsOptions.onDeny). - `UNAUTHORIZED_FIELD_OR_TYPE`: The `extensions.code` a denial carries under `onDeny: 'filter'`. - `FallbackError` (type): A replacement error for denials that did not name one: an `Error`, a message, or a mapper that receives the original error and the resolver arguments. - `granted`: A CheckableRule that passes when the field's `parent` was granted `scope` earlier in this request, and denies with `Forbidden` otherwise. - `grants`: Wraps a rule so that, when it passes and the resolver returns, what it returned is **granted** `scope` for the rest of the request — the object itself, or each object of a list. - `GraphQLAbilities` (type): The CASL ability-tuple union derived from a SubjectMap: each subject name `K` is paired with both its `__typename`-tagged object type and the bare string literal, plus a `[Action, 'all']` member for `manage`/`all`-style rules. - `GraphQLAbility` (type): A CASL MongoAbility whose conditions are statically typed against your schema. - `GraphQLAbilityOptions` (type): Options accepted by buildGraphQLAbility / the builder's `build()`. - `GraphQLRule` (type): A single serializable permission rule for a GraphQLAbility. - `buildGraphQLAbility`: Reconstructs a GraphQLAbility from previously-stored GraphQLRules — the path for loading rules persisted in a database (and caching them) at app start. - `createGraphQLAbility`: Creates a CASL `AbilityBuilder` typed against your SubjectMap, with `__typename` detection applied by `build()` (the mongo conditions matcher is built in). - `validatePermissions`: Checks a PermissionsMap against a schema and throws PermissionsError if anything in it is stale — without building any middleware. - `PermissionsError`: Thrown by applyPermissions / validatePermissions when a permissions map does not line up with the schema, and by validateGraphQLRules when stored ability rules do not. - `AnyResolvers` (type): The loose stand-in for a generated `Resolvers` type. - `CacheKey` (type): A custom cache key for rule's `cache` option — the same escape hatch `graphql-shield` offers when a function is passed as `cache`. - `Check` (type): The predicate behind a CheckableRule: the standard resolver arguments *without* `resolve`, answering "may this field be resolved?". - `CheckableRule` (type): A Rule that also exposes its decision as a standalone Check. - `PermissionsMap` (type): The permissions map applied to a schema via `applyPermissions`. - `Rule` (type): The callable middleware form used in PermissionsMap entries. - `RuleOptions` (type): Options for rule. - `RuleResult` (type): What a Check may return. - `Wildcard` (type): The wildcard key, usable in place of a type name or a field name in a PermissionsMap. - `accept`: An always-pass CheckableRule: invokes the wrapped resolver unconditionally. - `CacheMode`: How long one rule may reuse a check's answer. - `deny`: An always-fail CheckableRule: denies with `Forbidden` without invoking the resolver. - `isCheckableRule`: Narrows a Rule to a CheckableRule. - `rule`: Wraps a Check into a CheckableRule — a rule usable directly in a `PermissionsMap` *and* as an operand of the combinators. - `WILDCARD`: The Wildcard key as a value, for code that builds or reads a PermissionsMap by key. - `ArgsOf` (type): Extracts the args type from a generated resolver field. - `ContextOf` (type): Extracts the context type from a generated resolver field. - `ParentOf` (type): Extracts the parent (the object being resolved) from a generated resolver field. - `SubjectMap` (type): Maps each domain name to a `Partial` of its model type via `TResolversTypes`. - `SubjectName` (type): Derives the domain type names from any generated `Resolvers` type. - `createSubjects`: Returns a helper that validates a subject-name const object against the keys of `TMap`. - `createTyped`: Returns a `typed(type, attrs)` helper bound to a specific subject map. - `Subjects` (type): A subject-name namespace: every key of `TMap` mapped to its own name as a string literal. - `subjectsOf`: Returns a Subjects namespace for `TMap` — autocompleted, typo-proof subject names, with nothing to declare. - `ArgumentIssue` (type): One validation problem, as reported under `extensions.issues` of the error validateArgs throws. - `StandardSchemaV1` (type): The Standard Schema interface. - `ValidateArgsOptions` (type): Options for validateArgs. - `ValidatedArgs` (type): The arguments type a resolver behind `validateArgs(schema)` receives: the schema's *output* type. - `BAD_USER_INPUT`: The `extensions.code` a validateArgs failure carries — Apollo's conventional code for a request whose input is malformed, so clients that already branch on it need no new vocabulary. - `validateArgs`: A rule that validates a field's arguments against a Standard Schema, and on success calls the resolver with the parsed output as its `args`. - `ValidateGraphQLRulesOptions` (type): Options for validateGraphQLRules. - `validateGraphQLRules`: Checks stored GraphQLRules against a schema and throws PermissionsError if any of them could not do what it says. ## Exports: @vantreeseba/graphql-casl/scoping Argument scoping — the optional entry point, `@vantreeseba/graphql-casl/scoping`. - `OnDenyAll`: What scopeArgs does when the ability permits no row at all. - `ScopeOptions` (type): Options for scopeArgs. - `Scopable` (type): A `requireCan` from `createCan`, in either of its two shapes. - `scopeArgs`: A rule that narrows a field's filter argument to the rows the caller may `action`, instead of allowing or denying the field outright. ## Exports: @vantreeseba/graphql-casl/envelop The envelop integration — the optional entry point, `@vantreeseba/graphql-casl/envelop`. - `GraphQLCaslPluginOptions` (type): Options for useGraphQLCasl: the permissions map, plus every option `applyPermissions` accepts. - `useGraphQLCasl`: An envelop plugin that enforces a PermissionsMap. ## Exports: @vantreeseba/graphql-casl/apollo The Apollo Server integration — the optional entry point, `@vantreeseba/graphql-casl/apollo`. - `ApolloResponseBody` (type): The response body Apollo Server hands `willSendResponse`: the slice of its `GraphQLResponseBody` this plugin reads. - `ReportDenialsApolloPlugin` (type): The slice of Apollo Server's `ApolloServerPlugin` that reportDenialsPlugin implements. - `reportDenialsPlugin`: An Apollo Server plugin that reports the denials `onDeny: 'filter'` held for each request — the ones the response could not carry through the denied field itself — into the response before it is sent.