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

@axiomify/graphql

v7.0.0

Published

GraphQL plugin for Axiomify — schema-first, zero-boilerplate GraphQL endpoint with built-in GraphiQL playground.

Readme

@axiomify/graphql

npm version codecov OpenSSF Scorecard License: MIT

Drop-in GraphQL endpoint for Axiomify with a built-in GraphiQL playground, per-request context, and abuse-prevention controls.

Install

npm install @axiomify/graphql graphql

graphql is a peer dependency — install a ^16.0.0 version alongside this package.

Quick Start

import { Axiomify } from '@axiomify/core';
import { NativeAdapter } from '@axiomify/native';
import { buildSchema } from 'graphql';
import { useGraphQL } from '@axiomify/graphql';

const app = new Axiomify();

const schema = buildSchema(`
  type Query {
    hello: String
  }
`);

useGraphQL(app, { schema });

const adapter = new NativeAdapter(app, { port: 3000 });
adapter.listen(() => {
  console.log('GraphQL ready at http://localhost:3000/graphql');
  console.log('Playground at   http://localhost:3000/graphql/playground');
});

Exports

  • useGraphQL(app, options) — mounts the GraphQL endpoint
  • GraphQLPluginOptions — full options interface
  • GraphQLContextFactory — type for the context factory function
  • GraphQLResult — shape of every GraphQL response

Options

Defaults marked "prod / dev" differ by environment: the production value applies when NODE_ENV === 'production', otherwise the development value is used.

| Option | Type | Default | Description | | :--------------------- | :----------------------- | :---------------------------- | :----------------------------------------------------------------------- | | schema | GraphQLSchema | required | The compiled GraphQL schema to execute against. | | path | string | '/graphql' | HTTP path for the POST/GET endpoint. | | playground | boolean | false (prod) / true (dev) | Enable the GraphiQL browser UI. | | playgroundPath | string | '{path}/playground' | Path for the GraphiQL page. | | context | (req, res) => TContext | {} | Per-request context factory. Can be async. | | maxDepth | number | 12 (prod) / none (dev) | Reject queries deeper than this many levels. | | maxAliases | number | 15 (prod) / none (dev) | Reject queries with more aliases than this limit. | | maxFields | number | 100 (prod) / none (dev) | Reject queries with more fields than this limit (wide-query protection). | | maxQueryLength | number | 10000 | Reject a raw query string longer than this many characters (pre-parse). | | maxVariablesLength | number | 10000 | Reject serialized variables JSON longer than this many characters. | | disableIntrospection | boolean | true (prod) / false (dev) | Block introspection queries (__schema, __type). | | validationRules | array | [] | Additional GraphQL validation rules beyond the spec defaults. |

Endpoints

Three routes are registered automatically:

POST /graphql

The primary query endpoint. Accepts a JSON body:

{
  "query": "query GetUser($id: ID!) { user(id: $id) { name } }",
  "variables": { "id": "42" },
  "operationName": "GetUser"
}

GET /graphql

Accepts the same fields as query-string parameters. Useful for introspection tooling and simple queries:

GET /graphql?query={hello}

GET /graphql/playground

Serves a self-contained GraphiQL 3 UI. Disable with playground: false.

Context Factory

The context option receives the full AxiomifyRequest and AxiomifyResponse and can return any value. It runs once per request before the resolver tree executes.

useGraphQL(app, {
  schema,
  context: async (req) => {
    const token = req.headers['authorization']?.replace('Bearer ', '');
    const user = token ? await verifyToken(token) : null;
    return { user, db };
  },
});

If the factory throws, the request is rejected with HTTP 500 before the schema is touched.

Query Limits & Abuse Prevention

Without limits, a malicious client can craft deeply nested, heavily aliased, or wide queries that are cheap to send but expensive to resolve.

useGraphQL(app, {
  schema,
  maxDepth: 8, // rejects: { a { b { c { d { e { f { g { h { value } } } } } } } } }
  maxAliases: 15, // rejects: { a1: field a2: field ... a16: field }
  maxFields: 100, // rejects queries selecting more than 100 fields total
});

maxDepth, maxAliases, and maxFields are enforced as validation rules, so they run alongside the standard GraphQL spec rules with no separate schema pass. In production (NODE_ENV === 'production') they default to 12, 15, and 100 respectively; in development they are disabled unless set explicitly.

Raw input size limits

Two length checks run before the query is parsed, so an oversized payload can never reach the parser (CWE-400):

  • maxQueryLength (default 10000) — rejects a raw query string longer than this many characters with HTTP 400.
  • maxVariablesLength (default 10000) — rejects serialized variables JSON longer than this many characters with HTTP 400.
useGraphQL(app, {
  schema,
  maxQueryLength: 20000,
  maxVariablesLength: 5000,
});

Introspection

Introspection (__schema, __type) is disabled by default in production and enabled in development. It exposes your full schema to any client, so keep it off in production unless you have a reason to expose it:

useGraphQL(app, {
  schema,
  disableIntrospection: true, // force-off regardless of NODE_ENV
});

Custom Validation Rules

Pass extra validation rules that run alongside the standard GraphQL spec rules:

import { NoSchemaIntrospectionCustomRule } from 'graphql';

useGraphQL(app, {
  schema,
  validationRules: [NoSchemaIntrospectionCustomRule], // disable introspection in prod
});

Error Handling

Per the GraphQL spec, resolver errors are returned as HTTP 200 with an errors array:

{
  "data": { "user": null },
  "errors": [{ "message": "User not found", "path": ["user"] }]
}

Only malformed requests (unparseable query, failed validation, bad variables JSON) return 4xx status codes.

Example: Full Setup

import { Axiomify } from '@axiomify/core';
import { NativeAdapter } from '@axiomify/native';
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { useGraphQL } from '@axiomify/graphql';

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      hello: {
        type: GraphQLString,
        resolve: (_root, _args, ctx) =>
          `Hello, ${ctx.user?.name ?? 'stranger'}`,
      },
    },
  }),
});

const app = new Axiomify();

useGraphQL(app, {
  schema,
  path: '/graphql',
  playground: true,
  maxDepth: 10,
  maxAliases: 20,
  context: async (req) => ({
    user: await getUserFromHeader(req.headers['authorization']),
  }),
});

const adapter = new NativeAdapter(app, { port: 3000 });
adapter.listen(() => console.log('Ready'));