Repository navigation
envelop.Function.useGraphQLCasl
function useGraphQLCasl<TResolvers, TContext>(options): Plugin<TContext>;Defined in: packages/graphql-casl/src/envelop.ts:91
An envelop plugin that enforces a PermissionsMap.
TResolvers
Your generated Resolvers type.
TContext extends Record<string, any> = Record<string, any>
The plugin's context type.
GraphQLCaslPluginOptions<TResolvers>
The map and the ApplyPermissionsOptions.
Plugin<TContext>
The envelop plugin.
PermissionsError if the map does not line up with the schema.
The map is validated against the schema as soon as envelop provides one, so a
map naming a type or field the schema does not have throws a PermissionsError
at that point rather than mid-query. A schema swapped at runtime is
re-validated and re-resolved.
Introspection is never guarded, and a field with no resolver of its own is
guarded too — the default resolver is wrapped like any other, which is what
makes a canUser.fields(...) rule on a plain object type work here.
const getEnveloped = envelop({
plugins: [useSchema(schema), useGraphQLCasl<Resolvers>({ permissions })],
});