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

@occupop/lib-graphql

v3.0.1

Published

library used by microservices

Downloads

99

Readme

Claro! Aqui está o README.md traduzido para o inglês:

# GraphQL Server Library

A library to set up a GraphQL server with Apollo Server, Express, and various useful configurations.

## Installation

```bash
npm install @kaueoccupop/lib-graphql

Usage

Basic Configuration

Create and configure a GraphQL server with type definitions, resolvers, and context.

import express from 'express';
import { makeGraphqlServer, GraphqlServerInputParams } from '@kaueoccupop/lib-graphql';
import { typeDefs, resolvers } from './schema';
import { contextFunction } from './context';

const app = express();

const params: GraphqlServerInputParams = {
  port: 4000,
  sensitiveRoutesConfig: {
    '/auth/login': ['password'],
    '/auth/register': ['password', 'ssn'],
  },
  routeConfig: {
    router: express.Router(),
    prefix: '/api',
  },
  routes: [
    {
      method: 'post',
      path: '/custom-endpoint',
      handlers: [
        (req, res) => {
          res.send('Hello from custom endpoint!');
        },
      ],
    },
  ],
};

makeGraphqlServer({
  contextFunction,
  app,
  typeDefs,
  resolvers,
})(params).then(() => {
  console.log('Server is running...');
});

Folder Structure

  • src/
    • index.ts (main file)
    • schema.ts (type definitions and resolvers)
    • context.ts (context function)
    • middleware/
      • logRouteMiddleware.ts (middleware for route logging)

Configurations

GraphqlServerInputParams

| Property | Type | Description | |------------------------|-------------------------------|-------------------------------------------------------------------------------------------------| | port | number | Port where the server will run | | routeConfig | RoutingConfig | Express router configuration | | middlewares | ApplicationRequestHandler[] | List of express middlewares | | routes | HttpRoute[] | Custom route definitions | | errorRequestHandler | ErrorRequestHandler | Custom error handler | | sensitiveRoutesConfig| SensitiveRouteConfig | Configuration for routes and sensitive fields to be masked in logs |

SensitiveRouteConfig

An object mapping routes to a list of sensitive fields that should be masked in the logs.

const sensitiveRoutesConfig: SensitiveRouteConfig = {
  '/auth/login': ['password'],
  '/auth/register': ['password', 'ssn'],
};

Publishing to npm

To publish the library to npm, follow these steps:

  1. Configure package.json

Ensure your package.json is correctly configured with the name, version, and other necessary information.

{
  "name": "@kaueoccupop/lib-graphql",
  "version": "1.0.0",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "build": "tsc",
    "prepublishOnly": "npm run build",
    "test": "jest",
    "cover": "jest --coverage"
  },
  "files": [
    "dist"
  ],
  "devDependencies": {
    "typescript": "^5.3.3",
    "ts-jest": "^29.1.2",
    "jest": "^29.7.0",
    "@types/jest": "^29.5.12"
  },
  "dependencies": {
    "@apollo/server": "^4.10.1",
    "@apollo/subgraph": "^2.7.1",
    "express": "^4.18.3",
    "cors": "^2.8.5",
    "helmet": "^7.1.0",
    "graphql": "^16.8.1",
    "body-parser": "^1.20.2",
    "dotenv": "^16.4.5",
    "express-rate-limit": "^7.2.0",
    "awilix": "^10.0.2"
  }
}
  1. Compile the Code

Compile your TypeScript code to JavaScript.

npm run build
  1. Publish to npm

Log in to your npm account and publish the library.

npm login
npm run publish:npm

Notes

  • Helmet: Used to set security-related HTTP headers.
  • Rate Limit: Limits the number of requests per time window.
  • CORS: Enables CORS for all routes.
  • Health Check: Health check endpoint configured at /health.
  • Route Logging: Middleware for logging request and response details.

Configuration Examples

Type Definitions and Resolvers

// schema.ts
import { gql } from '@apollo/server';

export const typeDefs = gql`
  type Query {
    hello: String
  }
`;

export const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

Context Function

// context.ts
import { ExpressContextFunctionArgument } from '@apollo/server/express4';

export const contextFunction = ({ req, res }: ExpressContextFunctionArgument) => {
  return {
    authUser: req.user,
    container: req.container,
  };
};

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

If you would like to contribute to the project, follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b my-feature.
  3. Make your changes and commit them: git commit -m 'My new feature'.
  4. Push to the branch: git push origin my-feature.
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


I hope this `README.md` helps to document your project clearly and completely.