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

v0.0.1

Published

> Pre-built plugins for common GraphQL patterns

Readme

@graphjson/presets

Pre-built plugins for common GraphQL patterns

npm version License: MIT TypeScript

GraphJSON Presets provides ready-to-use plugins for common GraphQL patterns like Relay pagination, eliminating boilerplate and ensuring consistency.

Why Use This?

  • 🎯 Relay Pagination - Automatic edges/nodes/pageInfo structure
  • 🔌 Plugin-Based - Works with the GraphJSON plugin system
  • Zero Config - Works out of the box
  • 🎨 Customizable - Extend or create your own presets
  • 📦 Lightweight - Minimal dependencies

Installation

npm install @graphjson/presets @graphjson/core

Quick Start

import { generateDocument, applyPlugins } from '@graphjson/core';
import { relayPagination } from '@graphjson/presets';

// Generate a basic query
const { ast } = generateDocument({
  query: {
    posts: {
      args: { first: 20 },
      select: {
        id: true,
        title: true
      }
    }
  }
});

// Apply Relay pagination preset
const relayQuery = applyPlugins(ast, [relayPagination()]);

// Result now includes edges { node { ... } } and pageInfo structure

Available Presets

relayPagination()

Transforms queries to follow the Relay pagination specification.

Before:

query {
  posts(first: 20) {
    id
    title
  }
}

After:

query {
  posts(first: 20) {
    edges {
      node {
        id
        title
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

Usage

With generateDocument

import { generateDocument, applyPlugins } from '@graphjson/core';
import { relayPagination } from '@graphjson/presets';

const query = {
  query: {
    users: {
      args: { first: 10 },
      select: {
        id: true,
        name: true
      }
    }
  }
};

const { ast } = generateDocument(query);
const transformed = applyPlugins(ast, [relayPagination()]);

With SDK

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

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

Relay Pagination Details

What It Does

The relayPagination() preset automatically wraps your field selection with the Relay connection structure:

Original Field:

{
  "posts": {
    "select": {
      "id": true,
      "title": true
    }
  }
}

Transformed:

{
  "posts": {
    "select": {
      "edges": {
        "select": {
          "node": {
            "select": {
              "id": true,
              "title": true
            }
          }
        }
      },
      "pageInfo": {
        "select": {
          "hasNextPage": true,
          "endCursor": true
        }
      }
    }
  }
}

When to Use

Use Relay pagination when:

  • ✅ Your API follows Relay cursor connections spec
  • ✅ You need cursor-based pagination
  • ✅ You want pageInfo metadata
  • ✅ You're using Relay or similar clients

Configuration

The preset works automatically with no configuration needed. It detects fields that should be paginated and applies the transformation.

Integration Examples

With Apollo Client

import { ApolloClient } from '@apollo/client';
import { generateDocument, applyPlugins } from '@graphjson/core';
import { relayPagination } from '@graphjson/presets';

const { ast } = generateDocument(query);
const relayAst = applyPlugins(ast, [relayPagination()]);

const result = await client.query({
  query: relayAst,
  variables: { first: 20 }
});

// Access paginated data
const posts = result.data.posts.edges.map(edge => edge.node);
const hasMore = result.data.posts.pageInfo.hasNextPage;

With React

import { useState } from 'react';

function PostsList() {
  const [cursor, setCursor] = useState(null);
  
  const loadMore = async () => {
    const { ast } = generateDocument(postsQuery);
    const relayAst = applyPlugins(ast, [relayPagination()]);
    
    const result = await client.query({
      query: relayAst,
      variables: { first: 20, after: cursor }
    });
    
    const { edges, pageInfo } = result.data.posts;
    const newPosts = edges.map(e => e.node);
    
    if (pageInfo.hasNextPage) {
      setCursor(pageInfo.endCursor);
    }
    
    return newPosts;
  };
  
  // ... render logic
}

Creating Custom Presets

You can create your own presets following the plugin interface:

import type { GraphJsonPlugin } from '@graphjson/plugins';

export function customPreset(): GraphJsonPlugin {
  return {
    onDocument(document) {
      // Transform entire document
      return modifiedDocument;
    },
    onField(field, context) {
      // Transform individual fields
      return modifiedField;
    }
  };
}

Example - Add timestamp to all queries:

export function addTimestamp(): GraphJsonPlugin {
  return {
    onField(field) {
      if (!field.selectionSet) return field;
      
      return {
        ...field,
        selectionSet: {
          ...field.selectionSet,
          selections: [
            ...field.selectionSet.selections,
            {
              kind: Kind.FIELD,
              name: { kind: Kind.NAME, value: 'timestamp' }
            }
          ]
        }
      };
    }
  };
}

GraphJSON Ecosystem

| Package | Description | NPM | |---------|-------------|-----| | @graphjson/core | Core document generation | npm | | @graphjson/plugins | Plugin system types | npm | | @graphjson/sdk | High-level SDK | npm |

Examples

See the examples directory:

Contributing

Contributions are welcome! Please see CONTRIBUTING.md.

License

MIT © NexaLeaf