@giraphql/plugin-authz
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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

Setup

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'),
  }),
});

Package Sidebar

Install

npm i @giraphql/plugin-authz

Weekly Downloads

10

Version

2.0.0

License

ISC

Unpacked Size

81.3 kB

Total Files

37

Last publish

Collaborators

  • hayes