Repository navigation
envelop
The envelop integration — the optional entry point,
@vantreeseba/graphql-casl/envelop.
applyPermissions wraps a schema up front, which needs a schema you own
and can replace. That is awkward on Apollo Server 4+, on federated gateways,
and anywhere the schema is built or swapped for you. useGraphQLCasl
hooks resolvers as envelop hands them
over, so the same map works wherever envelop does — GraphQL Yoga, Apollo with
the envelop integration, Hive Gateway, graphql-ws.
The permission logic itself is not reimplemented here: the plugin calls
resolvePermissions, so wildcard precedence, fallbackRule coverage,
error control, filtering and map validation behave exactly as they do under
applyPermissions. One thing it can do that applyPermissions cannot: under
onDeny: 'filter' it sees the finished result, so the denials a field could
not carry itself are reported without any call to reportDenials.
@envelop/core and @envelop/on-resolve are optional peer dependencies —
they are only needed by consumers who import this entry point, which is why
the main entry point still has no runtime dependencies of its own.
import { createYoga } from 'graphql-yoga';
import { useGraphQLCasl } from '@vantreeseba/graphql-casl/envelop';
const yoga = createYoga({
schema,
plugins: [useGraphQLCasl<Resolvers>({ permissions, fallbackRule: deny })],
});