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

@graphjson/ast

v0.0.1

Published

> AST building utilities for GraphQL field nodes

Readme

@graphjson/ast

AST building utilities for GraphQL field nodes

npm version License: MIT TypeScript

Low-level AST building utilities for creating GraphQL field nodes from JSON structures. This package is used internally by @graphjson/core but can also be used standalone for custom AST manipulation.

Why Use This?

  • 🏗️ AST Building - Create GraphQL AST nodes from JSON
  • 🔧 Low-Level Control - Direct AST manipulation
  • 🎯 Type-Safe - Full TypeScript support
  • Efficient - Optimized for performance
  • 🔌 Composable - Use with GraphQL's visit function

Installation

npm install @graphjson/ast @graphjson/json-dsl

Quick Start

import { buildFieldNode } from '@graphjson/ast';
import type { JsonField } from '@graphjson/json-dsl';

const field: JsonField = {
  args: { id: '123' },
  select: {
    id: true,
    name: true
  }
};

const variables = new Map();
const collectVar = (name, v) => variables.set(name, v);

const fieldNode = buildFieldNode('user', field, collectVar);

API Reference

buildFieldNode(name, field, collectVar): FieldNode

Builds a GraphQL FieldNode from a JSON field definition.

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | name | string | Field name | | field | JsonField | JSON field definition | | collectVar | CollectVar | Callback for variable collection |

Returns: FieldNode - GraphQL AST field node

Example:

const fieldNode = buildFieldNode('users', {
  args: { limit: 10 },
  select: {
    id: true,
    name: true
  }
}, collectVar);

Usage

Building Simple Fields

import { buildFieldNode } from '@graphjson/ast';

const vars = new Map();
const collectVar = (name, v) => vars.set(name, v);

const node = buildFieldNode('user', {
  select: {
    id: true,
    name: true
  }
}, collectVar);

// Result: FieldNode for { id, name }

With Arguments

const node = buildFieldNode('users', {
  args: {
    limit: 10,
    offset: 0
  },
  select: {
    id: true,
    name: true
  }
}, collectVar);

// Result: users(limit: 10, offset: 0) { id, name }

With Variables

const node = buildFieldNode('user', {
  args: {
    id: { $var: 'userId', type: 'ID!' }
  },
  select: {
    id: true,
    name: true
  }
}, collectVar);

// collectVar will be called with ('userId', { $var: 'userId', type: 'ID!' })
// Result: user(id: $userId) { id, name }

Nested Fields

const node = buildFieldNode('user', {
  select: {
    id: true,
    posts: {
      args: { first: 10 },
      select: {
        title: true,
        content: true
      }
    }
  }
}, collectVar);

Advanced Usage

Custom AST Transformation

import { visit, Kind } from 'graphql';
import { buildFieldNode } from '@graphjson/ast';

const fieldNode = buildFieldNode('users', field, collectVar);

// Transform with GraphQL's visit
const transformed = visit(fieldNode, {
  Field(node) {
    // Custom transformation logic
    return modifiedNode;
  }
});

Variable Collection

const variables = new Map<string, any>();

const collectVar = (name: string, v: JsonVariable) => {
  variables.set(name, v.default ?? null);
};

buildFieldNode('user', field, collectVar);

// Access collected variables
console.log(Object.fromEntries(variables));

TypeScript Support

import type { JsonField } from '@graphjson/json-dsl';
import type { FieldNode } from 'graphql';

function buildCustomField(name: string, field: JsonField): FieldNode {
  const vars = new Map();
  return buildFieldNode(name, field, (n, v) => vars.set(n, v));
}

GraphJSON Ecosystem

| Package | Description | NPM | |---------|-------------|-----| | @graphjson/json-dsl | Type definitions | npm | | @graphjson/core | Core document generation | npm | | @graphjson/printer | Query printer | npm |

Contributing

Contributions are welcome! Please see CONTRIBUTING.md.

License

MIT © NexaLeaf