@soda-gql/cli

Command-line interface for soda-gql code generation.

Work in Progress

This documentation is being developed.

Installation

bun add -D @soda-gql/cli

Commands

codegen

Generate the type-safe GraphQL system from your schema:

bun run soda-gql codegen

Options

OptionDescription
--config <path>Path to config file (default: soda-gql.config.ts)
--emit-inject-template <path>Generate scalar/adapter template file
--prebuiltGenerate prebuilt types module alongside regular output

Subcommand: codegen graphql

Generate TypeScript compat code from existing .graphql operation files:

bun run soda-gql codegen graphql --input "src/**/*.graphql" --output src/generated

This is useful for:

  • Migrating existing GraphQL operations to soda-gql
  • Teams preferring to write operations in .graphql files
  • Gradual adoption of the soda-gql type-safe API

Options:

OptionDescription
--config <path>Path to config file
--schema <name>Schema name (required if multiple schemas configured)
--input <glob>Glob pattern for .graphql files (repeatable)
--output <dir>Output directory for generated files

Example:

Given src/queries/GetUser.graphql:

query GetUser($id: ID!) {
  user(id: $id) {
    id
    name
  }
}

Running:

bun run soda-gql codegen graphql --input "src/queries/*.graphql" --output src/generated

Generates src/generated/GetUser.compat.ts:

import { gql } from "../graphql-system";

export const GetUserCompat = gql.default(({ query, $var }) =>
  query.compat({
    name: "GetUser",
    variables: { ...$var("id").ID("!") },
    fields: ({ f, $ }) => ({
      ...f.user({ id: $.id })(({ f }) => ({
        ...f.id(),
        ...f.name(),
      })),
    }),
  }),
);

builder

Generate runtime artifacts during development:

bun run soda-gql builder --mode runtime --entry ./src/**/*.ts --out ./.cache/soda-gql/runtime.json

Configuration

Create a soda-gql.config.ts file:

import { defineConfig } from "@soda-gql/config";

export default defineConfig({
  outdir: "./src/graphql-system",
  include: ["./src/**/*.ts"],
  schemas: {
    default: {
      schema: "./schema.graphql",
      inject: "./src/graphql-system/default.inject.ts",
    },
  },
});

See Also