跳到主要内容

GraphQL Middleware

根据 GraphQL’s authorization guidance,授权应该位于一个地方——在 GraphQL 层和你的 resolvers 之间。在 resolvers(或一个薄包装器)中使用 Casbin 来对 types、fields 或 operations 执行访问控制。

// Casbin authorization logic lives inside postRepository
var postRepository = require('postRepository');

var postType = new GraphQLObjectType({
name: 'Post',
fields: {
body: {
type: GraphQLString,
resolve: (post, args, context, { rootValue }) => {
return postRepository.getBody(context.user, post);
}
}
}
});

Available GraphQL Middlewares​

可用的 Casbin GraphQL integrations:

MiddlewareGraphQL ImplementationAuthorDescription
graphql-authzgraphqlCasbingraphql-go 的授权中间件
graphql-casbingraphql@esmaeilpourGraphQL 和 Casbin 集成示例
gqlgen_casbin_RBAC_examplegqlgen@WenyXu(空)

Comments are powered by giscus and GitHub Discussions. They load from giscus.app and GitHub only after you click the button below.