2.0.0 • Published 4 years ago
@giraphql/plugin-authz v2.0.0
AuthZ plugin
This is a simple plugin for integrating with GraphQL AuthZ
For more details on GraphQL AuthZ see the official documentation here
Usage
Install
yarn add @giraphql/plugin-authzSetup
import AuthzPlugin from '@giraphql/plugin-authz';
const builder = new SchemaBuilder<{
  AuthZRule: keyof typeof rules;
}>({
  plugins: [AuthzPlugin],
});Defining rules for fields
builder.queryType({
  fields: (t) => ({
    users: t.field({
      type: [User],
      authz: {
        rules: ['IsAuthenticated'],
      },
      resolve: () => users,
    }),
  }),
});Defining rules for types
const Post = builder.objectRef<IPost>('Post');
Post.implement({
  authz: {
    rules: ['CanReadPost'],
  },
  fields: (t) => ({
    id: t.exposeID('id'),
  }),
});2.0.0
4 years ago