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

@soda-gql/sdk

v0.11.26

Published

Programmatic SDK for soda-gql CLI features

Readme

@soda-gql/sdk

npm version License: MIT

Programmatic API for soda-gql prebuild and codegen operations.

Installation

bun add @soda-gql/sdk

Overview

This package provides a programmatic interface to soda-gql's build system, allowing external tools and build plugins to execute artifact generation without invoking the CLI.

Key Features:

  • Synchronous and asynchronous build APIs (prebuild, prebuildAsync)
  • Programmatic code generation from GraphQL schemas (codegenAsync)
  • Optional context transformation for modifying composer context
  • Configurable build options (force rebuild, evaluator ID, entrypoints override)
  • Comprehensive error handling with typed Result

Usage

Basic Usage

import { prebuild, prebuildAsync } from "@soda-gql/sdk";

// Synchronous build
const result = prebuild({
  configPath: "./soda-gql.config.ts",
});

if (result.isOk()) {
  const { artifact } = result.value;
  console.log(`Built ${Object.keys(artifact.elements).length} elements`);
} else {
  console.error("Build failed:", result.error);
}

// Asynchronous build
const asyncResult = await prebuildAsync({
  configPath: "./soda-gql.config.ts",
});

With Context Transformer

import { prebuildAsync } from "@soda-gql/sdk";

const result = await prebuildAsync({
  configPath: "./soda-gql.config.ts",
  contextTransformer: (context) => ({
    ...context,
    // Add custom context properties
    buildId: process.env.BUILD_ID,
    environment: "production",
  }),
});

With Build Options

import { prebuildAsync } from "@soda-gql/sdk";

const result = await prebuildAsync({
  configPath: "./soda-gql.config.ts",
  force: true, // Force rebuild, ignore cache
  evaluatorId: "my-build", // Custom evaluator ID for cache isolation
  entrypointsOverride: ["./src/graphql/**/*.ts"], // Override config.include
});

Code Generation

Generate GraphQL runtime modules programmatically:

import { codegenAsync } from "@soda-gql/sdk";

// Generate from config file
const result = await codegenAsync({
  configPath: "./soda-gql.config.ts",
});

if (result.isOk()) {
  console.log("Generated:", result.value.outPath);
  console.log("Schemas:", Object.keys(result.value.schemas));
} else {
  console.error("Codegen failed:", result.error);
}

// Without explicit config path (will search for config file)
const autoResult = await codegenAsync();

API Reference

prebuild(options: PrebuildOptions): Result<PrebuildResult, PrebuildError>

Synchronously builds GraphQL artifacts based on the provided configuration.

prebuildAsync(options: PrebuildOptions): Promise<Result<PrebuildResult, PrebuildError>>

Asynchronously builds GraphQL artifacts. Preferred for build plugins and tools.

codegenAsync(options?: CodegenSdkOptions): Promise<Result<CodegenSdkResult, CodegenSdkError>>

Generates GraphQL runtime modules from schemas defined in config. Wraps the CLI's codegen command for programmatic use.

Types

PrebuildOptions

| Property | Type | Required | Description | | -------------------- | ------------------------- | -------- | ---------------------------------------------- | | configPath | string | Yes | Path to soda-gql config file | | contextTransformer | ContextTransformer | No | Function to modify composer context | | force | boolean | No | Force rebuild, ignore cache (default: false) | | evaluatorId | string | No | Unique evaluator ID (default: "default") | | entrypointsOverride| string[] \| Set<string> | No | Override config.include patterns |

PrebuildResult

interface PrebuildResult {
  artifact: BuilderArtifact;
}

PrebuildError

Union type: ConfigError | BuilderError

ContextTransformer

type ContextTransformer = (
  context: Record<string, unknown>
) => Record<string, unknown>;

CodegenSdkOptions

| Property | Type | Required | Description | | ------------ | -------- | -------- | --------------------------------------------------- | | configPath | string | No | Path to soda-gql config file (searches if omitted) |

CodegenSdkResult

interface CodegenSdkResult {
  schemas: Record<string, {
    schemaHash: string;
    objects: number;
    enums: number;
    inputs: number;
    unions: number;
  }>;
  outPath: string;
  internalPath: string;
  injectsPath: string;
  cjsPath: string;
}

CodegenSdkError

Union type: ConfigError | CodegenError

Session Lifecycle

prebuild and prebuildAsync internally create a BuilderSession and always call dispose() after build completion (in a finally block).

What dispose() does:

  1. Cache Persistence: Saves incremental build cache to node_modules/.cache/soda-gql/builder/cache.json
  2. Exit Handler Cleanup: Unregisters from process exit handler to prevent duplicate saves

Notes:

  • When using SDK, dispose() is called automatically - no manual cleanup needed
  • Even if build fails, dispose is guaranteed to run via finally block
  • Cache is shared across builds with the same evaluatorId

Limitations

Concurrent Execution

Do not run multiple prebuild or prebuildAsync calls concurrently with different contextTransformer options. The context transformer uses global state and concurrent calls may result in incorrect context being applied.

Safe patterns:

  • Sequential builds with different transformers
  • Concurrent builds without transformers
  • Concurrent builds with the same transformer

Related Packages

License

MIT