Skip to content

index.Function.validatePermissions

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

Function: validatePermissions()

function validatePermissions<TResolvers>(schema, permissions): void;

Defined in: packages/graphql-casl/src/mapValidation.ts:462

Checks a PermissionsMap against a schema and throws PermissionsError if anything in it is stale — without building any middleware.

Type Parameters

TResolvers

TResolvers = AnyResolvers

Parameters

schema

GraphQLSchema

The schema to check against.

permissions

PermissionsMap<NoInfer<TResolvers>>

The map to check.

Returns

void

Throws

PermissionsError Aggregating every problem, not just the first.

Remarks

This is the cheap half of applyPermissions. That function validates and wraps a resolver for every guarded field, which is O(fields) and, with a fallbackRule set, means every field in the schema. The wrapping dominates by orders of magnitude: on a 4,400-type / 35,200-field generated CRUD schema, applyPermissions takes ~1.6s and this takes ~8ms. Validation is the half a test actually wants.

The check is the same one applyPermissions runs, so a map that passes here passes there.

Example

it('has no stale keys', () => {
  expect(() => validatePermissions(schema, permissions)).not.toThrow();
});

API Reference

Clone this wiki locally