Skip to content

envelop.Function.useGraphQLCasl

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

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.

Type Parameters

TResolvers

TResolvers

Your generated Resolvers type.

TContext

TContext extends Record<string, any> = Record<string, any>

The plugin's context type.

Parameters

options

GraphQLCaslPluginOptions<TResolvers>

The map and the ApplyPermissionsOptions.

Returns

Plugin<TContext>

The envelop plugin.

Throws

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

Remarks

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.

Example

const getEnveloped = envelop({
  plugins: [useSchema(schema), useGraphQLCasl<Resolvers>({ permissions })],
});

API Reference

Clone this wiki locally