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:
| Middleware | GraphQL Implementation | Author | Description |
|---|---|---|---|
| graphql-authz | graphql | Casbin | graphql-go 的授权中间件 |
| graphql-casbin | graphql | @esmaeilpour | GraphQL 和 Casbin 集成示例 |
| gqlgen_casbin_RBAC_example | gqlgen | @WenyXu | (空) |
| 中间件 | GraphQL 实现 | 作者 | 描述 |
|---|---|---|---|
| graphql-authz | GraphQL.js | Casbin | GraphQL.js 的 Casbin 授权中间件 |
| 中间件 | GraphQL 实现 | 作者 | 描述 |
|---|---|---|---|
| graphql-authz | GraphQL-core 3 | @Checho3388 | GraphQL-core 3 的 Casbin 授权中间件 |
Comments are powered by giscus and GitHub Discussions. They load from giscus.app and GitHub only after you click the button below.