Repository navigation
index.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.
TResolvers = AnyResolvers
GraphQLSchema
The schema to check against.
PermissionsMap<NoInfer<TResolvers>>
The map to check.
void
PermissionsError Aggregating every problem, not just the first.
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.
it('has no stale keys', () => {
expect(() => validatePermissions(schema, permissions)).not.toThrow();
});