Skip to content

CLI Tools

The @effect-gql/cli package provides command-line tools for common development tasks like generating GraphQL SDL from your code-first schema.

Terminal window
npm install @effect-gql/cli

Or use directly with npx:

Terminal window
npx @effect-gql/cli <command>

Generate GraphQL SDL (Schema Definition Language) files from your code-first schema without starting your server.

Terminal window
# Generate SDL to stdout
effect-gql generate-schema ./src/schema.ts
# Write to file
effect-gql generate-schema ./src/schema.ts -o schema.graphql
# Watch mode - regenerate on changes
effect-gql generate-schema ./src/schema.ts -o schema.graphql --watch
OptionDescription
-o, --output <file>Write SDL to file instead of stdout
--no-sortDon’t sort schema alphabetically (default: sorted)
-w, --watchWatch for changes and regenerate
-h, --helpShow help message

Your schema module should export one of:

// Option 1: Export builder
export const builder = GraphQLSchemaBuilder.empty.pipe(
query("hello", { ... }),
objectType({ ... })
)
// Option 2: Export schema
export const schema = builder.buildSchema()
// Option 3: Default export
export default builder

Scaffold a new Effect GraphQL project with your choice of server runtime.

Terminal window
# Basic usage
effect-gql create my-api --server-type node
# Short form
effect-gql create my-api -s bun
# Interactive mode (prompts for options)
effect-gql create
TypePackageBest For
node@effect-gql/nodeGeneral Node.js deployments
bun@effect-gql/bunBun runtime with native WebSocket support
express@effect-gql/expressIntegrating into existing Express apps
web@effect-gql/webCloudflare Workers, Deno, edge runtimes
OptionDescription
-s, --server-type <type>Server type: node, bun, express, or web (required)
-d, --directory <path>Target directory (default: ./<name>)
--monorepoCreate as a workspace package (auto-detected)
--skip-installSkip dependency installation
--package-manager <pm>Package manager: npm, pnpm, yarn, or bun
-i, --interactiveInteractive mode with prompts
-h, --helpShow help message

The CLI automatically detects if you’re inside a monorepo by looking for:

  • pnpm-workspace.yaml
  • package.json with workspaces field
  • turbo.json

When in a monorepo, @effect-gql/* dependencies use workspace:* instead of version numbers:

Terminal window
# Inside a pnpm monorepo
effect-gql create packages/api -s node --monorepo
// Generated package.json
{
"dependencies": {
"@effect-gql/core": "workspace:*",
"@effect-gql/node": "workspace:*",
// ...
}
}
my-api/
├── package.json
├── tsconfig.json
├── .gitignore
└── src/
└── index.ts # Server entry point with example schema
Terminal window
# Create a Node.js server
effect-gql create my-api --server-type node
# Create a Bun server in a specific directory
effect-gql create my-api -s bun -d ./packages/graphql
# Create an Express middleware project without installing deps
effect-gql create my-api -s express --skip-install
# Create a Cloudflare Worker
effect-gql create my-worker -s web
# Add to an existing monorepo
effect-gql create @myorg/api -s node -d packages/api --monorepo

In code-first GraphQL frameworks, the schema is typically built at runtime. This often means you need to:

  1. Start your server with all dependencies (database, external services, etc.)
  2. Mock or stub every Effect layer just to generate SDL

Effect GQL separates schema building from query execution. The R type parameter tracks service requirements, but these are only needed when resolvers actually run—not when constructing the schema structure.

import { generateSDL } from "@effect-gql/cli"
// This works without any DatabaseService layer!
const builder = GraphQLSchemaBuilder.empty.pipe(
query("users", {
type: S.Array(UserSchema),
// Resolver requires DatabaseService, but it's never executed
resolve: () =>
DatabaseService.pipe(
Effect.flatMap((db) => db.getUsers())
),
})
)
// buildSchema() is pure - no services needed
const schema = builder.buildSchema()
// Generate SDL without any layers
const sdl = generateSDL(schema)

This means you can:

  • Generate SDL in CI without database connections
  • Create schema introspection endpoints
  • Build documentation from schema
  • Validate schema changes in pull requests
name: Schema Check
on: [push, pull_request]
jobs:
schema:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
# Generate schema and check for uncommitted changes
- run: npx @effect-gql/cli generate-schema ./src/schema.ts -o schema.graphql
- run: git diff --exit-code schema.graphql

Add to your .husky/pre-commit:

#!/bin/sh
npx @effect-gql/cli generate-schema ./src/schema.ts -o schema.graphql
git add schema.graphql

Create a simple generation script:

scripts/generate-schema.ts
import { generateSDL } from "@effect-gql/cli"
import { builder } from "../src/schema"
import { writeFileSync } from "fs"
const sdl = generateSDL(builder.buildSchema())
writeFileSync("schema.graphql", sdl)
console.log("Generated schema.graphql")

Run with:

Terminal window
npx tsx scripts/generate-schema.ts