Vai al contenuto principale

GraphQL Middleware

Per GraphQL’s authorization guidance, authorization should live in one place—between the GraphQL layer and your resolvers. Use Casbin in resolvers (or a thin wrapper) to enforce access on types, fields, or 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

Available Casbin GraphQL integrations:

MiddlewareImplementazione GraphQLAutoreDescrizione
graphql-authzgraphqlCasbinAuthorization middleware for graphql-go
graphql-casbingraphql@esmaeilpourGraphQL and Casbin integration example
gqlgen_casbin_RBAC_examplegqlgen@WenyXu(vuoto)