Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

@graphql-authz/apollo-server-plugin

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-authz/apollo-server-plugin

Apollo Server plugin for graphql-authz

latest
Source
npmnpm
Version
3.1.3
Version published
Weekly downloads
1.5K
134.89%
Maintainers
1
Weekly downloads
 
Created
Source

@graphql-authz/apollo-server-plugin

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

Apply authZDirectiveTransformer to schema and add plugin to apollo-server

  import { makeExecutableSchema } from '@graphql-tools/schema';
  import { authZDirective } from '@graphql-authz/directive';
  import { authZApolloPlugin } from "@graphql-authz/apollo-server-plugin";

  const { authZDirectiveTransformer } = authZDirective();

  const schema = makeExecutableSchema({
    typeDefs,
    resolvers
  });
  
  const transformedSchema = authZDirectiveTransformer(schema);

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

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

Keywords

typescript

FAQs

Package last updated on 12 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts