A library providing a Passport.js strategy (GraphQLLocalStrategy) and context builder utilities for integrating authentication into GraphQL servers (Express + Apollo Server). Version 0.6.8 ships TypeScript types and supports Express 4.x, Passport 0.x, subscriptions-transport-ws 0.x, and ws 7.x / 8.x. It simplifies authenticating users via mutations by wrapping passport.authenticate and passport.login into promises accessible from the GraphQL context, and also supports session-based auth and subscription user resolution. Compared to alternatives like graphql-auth, it directly leverages the Passport.js ecosystem.
npm install graphql-passportNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up a basic GraphQL server with passport authentication using graphql-passport. Defines a local strategy, builds context, and implements login mutation.
Use createOnConnect to extract user during subscription connection; do not call authenticate/login in subscription resolvers.
Migrate to graphql-ws and use Apollo Server's built-in subscription support or a compatible plugin.
Always pass the full { req, res } object to buildContext.Use 'graphql-local' as the strategy name; if upgrading from 0.2.x, update calls to context.authenticate('graphql-local', ...).Add context.login(user) after successful authentication when sessions are enabled.
Ensure buildContext({ req, res }) is used in Apollo Server's context option.Register the strategy with passport.use before creating the Apollo Server.
Add app.use(passport.initialize()) and app.use(passport.session()) if using sessions.