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/sdk

v0.0.1

Published

> High-level type-safe SDK for building GraphQL queries programmatically

Downloads

130

Readme

@graphjson/sdk

High-level type-safe SDK for building GraphQL queries programmatically

npm version License: MIT TypeScript

The GraphJSON SDK provides a fluent, chainable API for building GraphQL queries with full TypeScript support. Build complex queries programmatically with autocomplete and type safety.

Why Use This?

  • 🎯 Type-Safe - Full TypeScript support with autocomplete
  • ⛓️ Chainable API - Fluent, readable query building
  • 🚀 Powerful - Supports all GraphQL features
  • 💡 IntelliSense - IDE autocomplete for all methods
  • 🔧 Flexible - Programmatic query construction

Installation

npm install @graphjson/sdk

Quick Start

import { query, field, variable } from '@graphjson/sdk';
import { generateDocument } from '@graphjson/core';

const myQuery = query({
  users: field()
    .args({
      limit: variable('limit', 'Int!', 10),
      search: variable('search', 'String')
    })
    .select({
      id: true,
      name: true,
      email: true
    })
});

const { ast, variables } = generateDocument(myQuery);

Features

1. Query Builder

Build queries with a fluent API:

import { query, field } from '@graphjson/sdk';

const q = query({
  posts: field()
    .args({ first: 20 })
    .select({
      id: true,
      title: true,
      author: field()
        .select({
          name: true,
          avatar: true
        })
    })
});

2. Field Chaining

Chain methods for complex fields:

field()
  .args({ limit: 10 })
  .select({ id: true, name: true })
  .alias('usersList')
  .directive('include', { if: true })
  .paginate('relay')

3. Variables

Type-safe variable creation:

import { variable } from '@graphjson/sdk';

variable('userId', 'ID!')              // Required
variable('limit', 'Int', 10)           // With default
variable('filter', 'UserFilterInput')  // Optional

4. Pagination

Built-in pagination support:

field()
  .paginate('relay')  // Adds edges/node/pageInfo
  .args({ first: 20 })
  .select({ id: true, title: true })

5. Where Helpers

Type-safe filter building:

import { where, eq, gt, and, or } from '@graphjson/sdk';

const filters = where({
  age: gt(18),
  status: eq('active'),
  role: or(['admin', 'moderator'])
});

API Reference

query(fields: Record<string, Field>): JsonDocument

Creates a query operation.

query({
  users: field().select({ id: true }),
  posts: field().select({ title: true })
})

mutation(fields: Record<string, Field>): JsonDocument

Creates a mutation operation.

mutation({
  createUser: field()
    .args({ input: variable('user', 'UserInput!') })
    .select({ id: true, name: true })
})

field(): FieldBuilder

Creates a field builder with chainable methods.

Methods:

| Method | Description | |--------|-------------| | .args(obj) | Add field arguments | | .select(obj) | Select subfields | | .alias(name) | Set field alias | | .directive(name, args) | Add directive | | .paginate(style) | Add pagination |

variable(name: string, type: string, defaultValue?: any): JsonVariable

Creates a GraphQL variable reference.

variable('userId', 'ID!')           // Required variable
variable('limit', 'Int', 10)        // With default value

Usage Examples

Basic Query

import { query, field } from '@graphjson/sdk';

const q = query({
  users: field().select({
    id: true,
    name: true,
    email: true
  })
});

With Arguments

const q = query({
  user: field()
    .args({ id: '123' })
    .select({
      id: true,
      name: true
    })
});

With Variables

import { query, field, variable } from '@graphjson/sdk';

const q = query({
  users: field()
    .args({
      limit: variable('pageSize', 'Int!', 20),
      offset: variable('offset', 'Int', 0)
    })
    .select({
      id: true,
      name: true
    })
});

Nested Fields

const q = query({
  posts: field()
    .select({
      id: true,
      title: true,
      author: field()
        .select({
          id: true,
          name: true
        }),
      comments: field()
        .args({ first: 10 })
        .select({
          text: true,
          author: field().select({ name: true })
        })
    })
});

With Aliases

const q = query({
  recentPosts: field()
    .alias('recent')
    .args({ first: 10, orderBy: 'CREATED_DESC' })
    .select({ id: true, title: true }),
  
  popularPosts: field()
    .alias('popular')
    .args({ first: 10, orderBy: 'VIEWS_DESC' })
    .select({ id: true, title: true })
});

With Directives

const q = query({
  user: field()
    .select({
      id: true,
      name: true,
      email: field()
        .directive('include', { if: true }),
      phone: field()
        .directive('skip', { if: false })
    })
});

Relay Pagination

const q = query({
  posts: field()
    .paginate('relay')
    .args({ first: 20 })
    .select({
      id: true,
      title: true,
      content: true
    })
});

// Generates query with edges/node/pageInfo structure

Where Filters

import { query, field, where, eq, gt, contains } from '@graphjson/sdk';

const q = query({
  users: field()
    .args({
      where: where({
        age: gt(18),
        status: eq('active'),
        name: contains('john')
      })
    })
    .select({
      id: true,
      name: true
    })
});

TypeScript Support

Full type inference and autocomplete:

import { query, field } from '@graphjson/sdk';

// TypeScript knows the structure
const q = query({
  users: field()
    .args({ /* autocomplete works here */ })
    .select({ /* and here */ })
});

GraphJSON Ecosystem

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

Examples

See the examples directory for complete examples:

Contributing

Contributions are welcome! Please see CONTRIBUTING.md.

License

MIT © NexaLeaf