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

@stonecrop/graphql-client

v0.11.0

Published

GraphQL client integration for Stonecrop

Readme

@stonecrop/graphql-client

Client-side TypeScript implementation of the DataClient interface for Stonecrop's PostGraphile-based GraphQL API. StonecropClient handles HTTP transport, response unwrapping, query building, and metadata caching so application code works with plain TypeScript objects.

Installation

pnpm add @stonecrop/graphql-client

Usage

import { StonecropClient } from '@stonecrop/graphql-client'
import { Registry, getStonecrop } from '@stonecrop/stonecrop'
import type { DoctypeMeta } from '@stonecrop/schema'

const registry = new Registry()
// ... register doctypes ...

// Build a DoctypeMeta map — StonecropClient expects DoctypeMeta, not Doctype instances
const metaMap = new Map<string, DoctypeMeta>()
for (const [slug, doctype] of Object.entries(registry.registry)) {
  metaMap.set(slug, {
    name: doctype.doctype,
    slug,
    tableName: slug.replace(/-/g, '_'),
    fields: doctype.getSchemaArray(),
    links: doctype.links || {},
  })
}

const client = new StonecropClient({
  endpoint: 'http://localhost:4000/graphql',
  headers: { Authorization: `Bearer ${token}` }, // optional
  registry: metaMap, // for nested query support
})

// Wire up the client to the Stonecrop instance
const stonecrop = getStonecrop()
if (stonecrop) {
  stonecrop.setClient(client)
}

Metadata

// Fetch DoctypeMeta for a single doctype (cached after first call)
const meta = await client.getMeta({ doctype: 'SalesOrder' })

// Fetch all registered doctypes
const allMeta = await client.getAllMeta()

// Bust the in-memory cache
client.clearMetaCache()

Reading Records

import { GetRecordOptions, GetRecordsOptions } from '@stonecrop/schema'

// Single record by ID (flat — scalar fields only)
const order = await client.getRecord({ name: 'SalesOrder' }, 'uuid-here')

// Single record with all nested descendant links
const recipe = await client.getRecord({ name: 'Recipe' }, 'r1', {
  includeNested: true,
})

// Single record with specific nested links only
const recipe = await client.getRecord({ name: 'Recipe' }, 'r1', {
  includeNested: ['tasks'],
})

// Single record with limited nesting depth
const recipe = await client.getRecord({ name: 'Recipe' }, 'r1', {
  includeNested: true,
  maxDepth: 2,
})

// List with optional filtering and pagination
const orders = await client.getRecords(
  { name: 'SalesOrder' },
  {
    filters: { status: 'Draft' },
    orderBy: 'createdAt',
    limit: 20,
    offset: 0,
  }
)

Actions

// Dispatch any registered action
const result = await client.runAction({ name: 'SalesOrder' }, 'submit', ['uuid-here'])
// → { success: boolean; data: unknown; error: string | null }

Raw GraphQL

For queries or mutations not covered by the helpers:

const data = await client.query<{ myTable: unknown[] }>(`query { myTable { id name } }`)

const result = await client.mutate<{ createFoo: unknown }>(
  `mutation CreateFoo($input: CreateFooInput!) { createFoo(input: $input) { foo { id } } }`,
  { input: { foo: { name: 'bar' } } }
)

How Nested Queries Work

When includeNested is set on getRecord:

  1. The client fetches doctype metadata (including links)
  2. Builds a GraphQL query with sub-selections for descendant links
  3. Connection fields (noneOrMany/atLeastOne) emit { nodes { ... } } sub-selections
  4. Direct fields (one/atMostOne) emit object sub-selections
  5. Results with connection fields are merged to flat arrays

Example query generated for a Recipe with tasks (noneOrMany) and supersededBy (atMostOne):

query GetRecord($id: UUID!) {
  recipeById(id: $id) {
    id
    name
    status
    RecipeTasksByRecipeId {
      nodes {
        id
        name
        description
      }
    }
    supersededBy {
      id
      name
      status
    }
  }
}

The response is merged so result.tasks is a flat array and result.supersededBy is a direct object.

References

For full method signatures and parameter details, see API Reference.