Casbin
PluginsMiddlewares

GraphQL

Authorization for GraphQL endpoints

Casbin follows the recommended GraphQL authorization pattern by implementing authorization as a single source of truth: https://graphql.org/learn/authorization/. This means Casbin logic should sit between the GraphQL layer and your business logic.

// 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

Below is a complete list of Casbin GraphQL middlewares. Third-party middleware contributions are welcome—please let us know and we'll include them here.

MiddlewareGraphQL ImplementationAuthorDescription
graphql-authzgraphqlCasbinAuthorization middleware for graphql-go
graphql-casbingraphql@esmaeilpourGraphQL and Casbin integration example
gqlgen_casbin_RBAC_examplegqlgen@WenyXu(empty)
MiddlewareGraphQL ImplementationAuthorDescription
graphql-authzGraphQL.jsCasbinCasbin authorization middleware for GraphQL.js
MiddlewareGraphQL ImplementationAuthorDescription
graphql-authzGraphQL-core 3@Checho3388Casbin authorization middleware for GraphQL-core 3

On this page