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

@webnt-dev/graphql-processor

v1.0.3

Published

Processing of graphql

Downloads

78

Readme

Package allows for simple GraphQL scheme definition, field handler functions and field directive functions.

Following code showcases

  • definition of GraphQL schema in schema constant
  • definition of GraphQL field handlers in handlers constant
  • definition of GraphQL directives handlers in directives constant

see below for more secription

See tests for more detailed examples!

import { gql, GraphQLDirectiveHandler, graphql, GraphQLHandler } from '@webnt-dev/graphql-processor';
import { GraphQLError } from 'graphql';


// GraphQL schema definition
const schema = gql`
  # directives are evaluated from right to left
  directive @whatever on FIELD_DEFINITION
  directive @role(role: String!) on FIELD_DEFINITION
  directive @upper on FIELD

  type Person {
    name: String!
    surname: String!
    fullname: String!
    secret: String! @whatever @role(role: "ADMIN")
  }
  type Query {
    get: Person!
  }

  schema {
    query: Query,
  }
`;

interface Person {
  name: string;
  surname: string;
  secret: string;
}

let person = {
  name: "John",
  surname: "Doe",
  secret: "123456789abcd",
}

const handlers: GraphQLHandler = {
  Person: {
    fullname(obj: Person): string {
      return `${obj.surname} ${obj.name}`;
    }
  },

  Query: {
    get(): Person {
      return person;
    }
  },
}


const directives: GraphQLDirectiveHandler = {
  role(resolve: ()=>any, obj: any, args: any, context: any): Promise<any> {
    if (args.role !== context.role) {
      throw new GraphQLError("Unauthorized", {
        extensions: {
          code: "E_ROLE",
        },
      });
    }
    return resolve();
  },

  async whatever(resolve: ()=>any): Promise<any> {
    return resolve();
  },

  async upper(resolve: ()=>any): Promise<string> {
    const result = await resolve();
    return result.toString().toUpperCase();
  },
}

const contextValue = {
  role: "ADMIN",
  extensions: {
    stack: []
  }
}

const result = await graphql({
  handlers,
  directives,
  schema,
  source: gql`
    query {
      get {
        name
        surname
        fullname
        secret @upper
      }
    }
  `,
  contextValue,
});

console.log(JSON.parse(JSON.stringify(result)));

How are handlers executed (order):

  1. get
  2. fullname
  3. upper
  4. role
  5. whatever

The way how directives works is they are calling resolvers left to it, lets assume following change:

# in schema
fullname: String! @whatever @role(role: "ADMIN")

# in query
fullname @upper

The order would be:

  1. get
  2. upper
  3. role
  4. whatever
  5. fullname

The upper is called first, it calles resolve() which triggers role, role calles resolve() as well, that triggers whatever, etc.

If any handler throws, processing stops, error is returned.

If any handler does not call resolve() and returns some other value, the following handlers are not called and the new value becomes overall result of field evaluation.

Supported directives

Currently only FIELD_DEFINITION and FIELD directives are supported

Field handler

Field handler are of type

type HandlerFunction = (obj: any, args: any, context: any, info: GraphQLResolveInfo) => unknown;
type AsyncHandlerFunction = (obj: any, args: any, context: any, info: GraphQLResolveInfo) => Promise<unknown>;

// handler is of type
HandlerFunction | AsyncHandlerFunction

See tests for more examples.

Directive handler

Field handler are of type

type DirectiveFunction = (resolve: ()=>any, obj: any, args: any, context: any, info: GraphQLResolveInfo, functionArgs: any) => unknown;
type AsyncDirectiveFunction = (resolve: ()=>any, obj: any, args: any, context: any, info: GraphQLResolveInfo, functionArgs: any) => Promise<unknown>;


// handler is of type
DirectiveFunction | AsyncDirectiveFunction

See tests for more examples.

Result

{
  "data": {
    "get": {
      "name": "John",
      "surname": "Doe",
      "fullname": "Doe John",
      "secret": "123456789ABCD"
    }
  }
}

Changelog

Any missing version means mostly documentation fixes.

version 1.0.2

  • overload function for graphql function @ package version 2025-03-12

version 1.0.0

2025-02-28

+ initial version