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/json-dsl

v0.0.1

Published

> TypeScript type definitions for the GraphJSON JSON DSL

Readme

@graphjson/json-dsl

TypeScript type definitions for the GraphJSON JSON DSL

npm version License: MIT TypeScript

Type definitions and interfaces for the GraphJSON JSON Domain Specific Language (DSL). This package provides TypeScript types for writing type-safe JSON-based GraphQL queries.

Why Use This?

  • 🎯 Full Type Safety - TypeScript definitions for all JSON query structures
  • 📝 IDE Autocomplete - IntelliSense support for query building
  • Compile-Time Validation - Catch errors before runtime
  • 📚 Self-Documenting - Types serve as documentation
  • 🔧 Foundation - Core types used across GraphJSON ecosystem

Installation

npm install @graphjson/json-dsl

Quick Start

import type { JsonDocument, JsonField, JsonVariable } from '@graphjson/json-dsl';

const query: JsonDocument = {
  query: {
    users: {
      args: {
        limit: { $var: 'limit', type: 'Int!', default: 10 }
      },
      select: {
        id: true,
        name: true
      }
    }
  }
};

Type Definitions

JsonDocument

Root type for a GraphJSON document.

interface JsonDocument {
  query?: Record<string, JsonField>;
  mutation?: Record<string, JsonField>;
  subscription?: Record<string, JsonField>;
}

Example:

const doc: JsonDocument = {
  query: {
    users: { select: { id: true } }
  },
  mutation: {
    createUser: {
      args: { input: { $var: 'user', type: 'UserInput!' } },
      select: { id: true }
    }
  }
};

JsonField

Represents a field with optional arguments and subfield selection.

interface JsonField {
  args?: Record<string, JsonValue | JsonVariable>;
  select?: Record<string, boolean | JsonField>;
}

Example:

const userField: JsonField = {
  args: { id: "123" },
  select: {
    id: true,
    name: true,
    posts: {
      args: { first: 10 },
      select: {
        title: true
      }
    }
  }
};

JsonVariable

Represents a GraphQL variable reference.

interface JsonVariable {
  $var: string;      // Variable name
  type: string;      // GraphQL type
  default?: any;     // Optional default value
}

Example:

const idVar: JsonVariable = {
  $var: 'userId',
  type: 'ID!',
  default: '123'
};

JsonValue

Union type for all possible JSON values.

type JsonValue =
  | string
  | number
  | boolean
  | null
  | JsonValue[]
  | { [key: string]: JsonValue };

Usage Examples

Type-Safe Query Building

import type { JsonDocument } from '@graphjson/json-dsl';

const query: JsonDocument = {
  query: {
    users: {
      select: {
        id: true,
        name: true,
        // TypeScript will error if you use invalid structure
      }
    }
  }
};

Field Definition

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

function createUserQuery(userId: string): JsonField {
  return {
    args: { id: userId },
    select: {
      id: true,
      name: true,
      email: true
    }
  };
}

Variable Helper

import type { JsonVariable } from '@graphjson/json-dsl';

function createVariable(
  name: string,
  type: string,
  defaultValue?: any
): JsonVariable {
  return {
    $var: name,
    type,
    ...(defaultValue !== undefined && { default: defaultValue })
  };
}

// Usage
const pageSize = createVariable('pageSize', 'Int!', 20);

Type Guards

import type { JsonVariable } from '@graphjson/json-dsl';

function isJsonVariable(value: any): value is JsonVariable {
  return (
    typeof value === 'object' &&
    value !== null &&
    '$var' in value &&
    typeof value.$var === 'string' &&
    'type' in value &&
    typeof value.type === 'string'
  );
}

// Usage
if (isJsonVariable(arg)) {
  console.log(`Variable: ${arg.$var} of type ${arg.type}`);
}

TypeScript Configuration

For best experience, ensure your tsconfig.json includes:

{
  "compilerOptions": {
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true
  }
}

GraphJSON Ecosystem

| Package | Description | NPM | |---------|-------------|-----| | @graphjson/core | Core document generation | npm | | @graphjson/ast | AST building utilities | npm | | @graphjson/sdk | High-level type-safe SDK | npm |

Contributing

Contributions are welcome! Please see CONTRIBUTING.md.

License

MIT © NexaLeaf