#!/usr/bin/env node /** * CLI entry point for graphql-codegen * * This is a thin wrapper around the core generate() function. * All business logic is in the core modules. */ import { CLI, CLIOptions, getPackageJson, Inquirerer } from 'inquirerer'; import { runCodegenHandler } from './handler'; const usage = ` graphql-codegen - GraphQL SDK generator for Constructive databases Usage: graphql-codegen [options] Source Options (choose one): -c, --config Path to config file -e, --endpoint GraphQL endpoint URL -s, --schema-file Path to GraphQL schema file --schema-dir Directory of .graphql files (auto-expands to multi-target) Database Options: --schemas Comma-separated PostgreSQL schemas --api-names Comma-separated API names (mutually exclusive with --schemas) Multiple apiNames auto-expand to multi-target (one schema per API). Generator Options: --react-query Generate React Query hooks --orm Generate ORM client -o, --output Output directory -t, --target Target name (for multi-target configs) -a, --authorization Authorization header value --dry-run Preview without writing files -v, --verbose Show detailed output Schema Export: --schema-enabled Export GraphQL SDL instead of running full codegen. Works with any source (endpoint, file, database, PGPM). With multiple apiNames, writes one .graphql per API. --schema-output Output directory for the exported schema file --schema-filename Filename for the exported schema (default: schema.graphql) -h, --help Show this help message --version Show version number `; export const commands = async ( argv: Record, prompter: Inquirerer, _options: CLIOptions, ): Promise> => { if (argv.version) { const pkg = getPackageJson(__dirname); console.log(pkg.version); process.exit(0); } if (argv.help || argv.h) { console.log(usage); process.exit(0); } await runCodegenHandler(argv, prompter); prompter.close(); return argv; }; export const options: Partial = { minimistOpts: { alias: { h: 'help', c: 'config', e: 'endpoint', s: 'schema-file', o: 'output', t: 'target', a: 'authorization', v: 'verbose', }, boolean: ['schema-enabled'], string: [ 'config', 'endpoint', 'schema-file', 'schema-dir', 'schema-output', 'schema-filename', 'output', 'target', 'authorization', 'schemas', 'api-names', ], }, }; if (require.main === module) { const cli = new CLI(commands, options); cli.run(); }