Skip to content

index.Function.resolvePermissions

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

Function: resolvePermissions()

function resolvePermissions<TResolvers>(
   schema, 
   permissions, 
   options?): PermissionResolver;

Defined in: packages/graphql-casl/src/applyPermissions.ts:322

Resolves a PermissionsMap against a schema into a per-field lookup, without applying it to anything.

Type Parameters

TResolvers

TResolvers = AnyResolvers

Your generated Resolvers type.

Parameters

schema

GraphQLSchema

The schema the map is checked against.

permissions

PermissionsMap<NoInfer<TResolvers>>

The permissions map to resolve.

options?

ApplyPermissionsOptions

Optional ApplyPermissionsOptions.

Returns

PermissionResolver

A lookup from type and field name to the rule guarding that field.

Throws

PermissionsError if the map does not line up with the schema.

Remarks

applyPermissions is this plus graphql-middleware. Use this directly to enforce the same map through another integration — an Apollo plugin, hand-wrapped resolvers — and get identical wildcard precedence, fallbackRule coverage, error control and masking, rather than a second implementation that drifts. The @vantreeseba/graphql-casl/envelop entry point is exactly that, already written.

The map is validated up front, exactly as applyPermissions validates it, so a mismatched map fails at wiring time rather than mid-query. Lookups are memoized, so calling this per resolver call is cheap.

Example

const permissionFor = resolvePermissions<Resolvers>(schema, permissions);
const rule = permissionFor(info.parentType.name, info.fieldName);
return rule ? rule(resolver, root, args, context, info) : resolver(root, args, context, info);

API Reference

Clone this wiki locally