npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@appforgeapps/shieldforge-graphql

v0.0.5

Published

GraphQL schema definitions and resolvers for ShieldForge authentication

Readme

@shieldforge/graphql

GraphQL schema definitions and resolvers for authentication.

Installation

npm install @shieldforge/graphql

Peer dependencies:

npm install graphql

Quick Start

Backend Setup

import { createResolvers, typeDefs } from '@shieldforge/graphql';
import { ShieldForge } from '@shieldforge/core';

const auth = new ShieldForge({
  jwtSecret: process.env.JWT_SECRET!,
});

// Implement data source
const dataSource = {
  getUserById: async (id) => await db.user.findUnique({ where: { id } }),
  getUserByEmail: async (email) => await db.user.findUnique({ where: { email } }),
  createUser: async (input) => await db.user.create({ data: input }),
  updateUser: async (id, input) => await db.user.update({ where: { id }, data: input }),
  createPasswordReset: async (userId, code, expiresAt) => {
    await db.passwordReset.create({ data: { userId, code, expiresAt } });
  },
  getPasswordReset: async (code) => {
    return await db.passwordReset.findUnique({ where: { code } });
  },
  deletePasswordReset: async (code) => {
    await db.passwordReset.delete({ where: { code } });
  },
};

// Create resolvers
const resolvers = createResolvers({
  dataSource,
  auth: {
    hashPassword: (password) => auth.hashPassword(password),
    verifyPassword: (password, hash) => auth.verifyPassword(password, hash),
    generateToken: (payload) => auth.generateToken(payload),
    verifyToken: (token) => auth.verifyToken(token),
    calculatePasswordStrength: (password) => auth.calculatePasswordStrength(password),
    sanitizeUser: (user) => auth.sanitizeUser(user),
    generateResetCode: () => auth.generateResetCode(),
    sendPasswordResetEmail: (to, code) => auth.sendPasswordResetEmail(to, code),
  },
});

// Use with Apollo Server
import { ApolloServer } from '@apollo/server';

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: ({ req }) => {
    const token = req.headers.authorization?.replace('Bearer ', '');
    if (token) {
      try {
        const payload = auth.verifyToken(token);
        return { userId: payload.userId, token };
      } catch (error) {
        return {};
      }
    }
    return {};
  },
});

Frontend Usage

import { LOGIN_MUTATION, REGISTER_MUTATION, ME_QUERY } from '@shieldforge/graphql';
import { useMutation, useQuery } from '@apollo/client';
import { useAuth } from '@shieldforge/react';

function LoginForm() {
  const [login, { loading, error }] = useMutation(LOGIN_MUTATION);
  const { login: authLogin } = useAuth();

  const handleSubmit = async (email: string, password: string) => {
    const { data } = await login({
      variables: { input: { email, password } }
    });
    
    authLogin(data.login.token, data.login.user);
  };

  return (/* your form */);
}

function Profile() {
  const { data, loading } = useQuery(ME_QUERY);
  
  if (loading) return <div>Loading...</div>;
  
  return <div>Email: {data.me.email}</div>;
}

Type Definitions

The package exports complete GraphQL schema:

  • User type
  • AuthPayload type
  • LoginInput, RegisterInput, UpdateProfileInput, UpdatePasswordInput
  • Query.me - Get current user
  • Query.checkPasswordStrength - Check password strength
  • Mutation.login - Login user
  • Mutation.register - Register user
  • Mutation.logout - Logout user
  • Mutation.updateProfile - Update user profile
  • Mutation.updatePassword - Change password
  • Mutation.requestPasswordReset - Request password reset
  • Mutation.resetPassword - Reset password with code

Documents

Pre-built query/mutation strings:

import {
  LOGIN_MUTATION,
  REGISTER_MUTATION,
  LOGOUT_MUTATION,
  ME_QUERY,
  UPDATE_PROFILE_MUTATION,
  UPDATE_PASSWORD_MUTATION,
  REQUEST_PASSWORD_RESET_MUTATION,
  RESET_PASSWORD_MUTATION,
  CHECK_PASSWORD_STRENGTH_QUERY,
  USER_FIELDS_FRAGMENT,
  AUTH_PAYLOAD_FRAGMENT,
} from '@shieldforge/graphql';

Extending the Schema

You can extend the User type with your own fields:

extend type User {
  customField: String
  anotherField: Int
}

Then update your data source to return the additional fields.

Data Source Interface

interface AuthDataSource {
  getUserById(id: string): Promise<User | null>;
  getUserByEmail(email: string): Promise<User | null>;
  createUser(input: RegisterInput & { passwordHash: string }): Promise<User>;
  updateUser(id: string, input: Partial<User>): Promise<User>;
  createPasswordReset(userId: string, code: string, expiresAt: Date): Promise<void>;
  getPasswordReset(code: string): Promise<{ userId: string; expiresAt: Date } | null>;
  deletePasswordReset(code: string): Promise<void>;
}

License

MIT