Repository navigation
index.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.
TResolvers = AnyResolvers
Your generated Resolvers type.
GraphQLSchema
The schema the map is checked against.
PermissionsMap<NoInfer<TResolvers>>
The permissions map to resolve.
Optional ApplyPermissionsOptions.
A lookup from type and field name to the rule guarding that field.
PermissionsError if the map does not line up with the schema.
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.
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);