@graphql-authz/apollo-server-v2-plugin

Apollo Server v2 plugin for graphql-authz

Usage no npm install needed!

<script type="module">
  import graphqlAuthzApolloServerV2Plugin from 'https://cdn.skypack.dev/@graphql-authz/apollo-server-v2-plugin';
</script>

README

@graphql-authz/apollo-server-plugin-v2

Configuring Apollo Server

Ensure context parser is configured to perform authentication and add user info to context

const server = new ApolloServer({
  ...
  context: ({ req }) => {
    return {
      user: someHowAuthenticateUser(req.get("authorization"))),
    };
  },
  ...
});

For Directives usage

Add plugin and directive visitor to apollo-server

  import { authZApolloPlugin, AuthZDirectiveVisitor } from "@graphql-authz/apollo-server-plugin";

  const server = new ApolloServer({
    ...
    plugins: [authZApolloPlugin({ rules })],
    schemaDirectives: { authz: AuthZDirectiveVisitor },
    ...
  });

For Extensions usage

Add plugin to apollo-server

  import { authZApolloPlugin } from "@graphql-authz/apollo-server-plugin";;

  const server = new ApolloServer({
    ...
    plugins: [authZApolloPlugin({ rules })],
    ...
  });

For AuthSchema usage

Add plugin to apollo-server with an additional parameter authSchema

  import { authZApolloPlugin } from "@graphql-authz/apollo-server-plugin";;

  const server = new ApolloServer({
    ...
    plugins: [authZApolloPlugin({ rules, authSchema })],
    ...
  });