feat(codegen): apiNames auto-expand, schemaDir, --schema-only, graphile-schema package, README headers#731
Merged
pyramation merged 23 commits intomainfrom Feb 19, 2026
Conversation
- Add cli config option (CliConfig | boolean) to GraphQLSDKConfigTarget - Add komoji dependency for toKebabCase casing - Create CLI generator orchestrator (cli/index.ts) - Create arg-mapper: converts CleanTypeRef to inquirerer Question[] - Create infra-generator: context + auth commands via Babel AST - Create executor-generator: ORM client init with appstash credentials - Create table-command-generator: per-table CRUD using ORM methods - Create custom-command-generator: per-operation using ORM methods - Create command-map-generator: command registry (Record<string, Function>) - Wire CLI generation into generate.ts alongside ORM/React Query - Update root barrel to include CLI exports Architecture: CLI -> ORM -> GraphQL (not CLI -> raw GraphQL) CLI commands: prompt for args -> call ORM method -> print JSON result Uses appstash@0.4.0 config-store for context/credential management
- Add cli-generator.test.ts with 13 tests covering all generated files - Snapshot executor, context, auth, table commands, custom commands, command map - Verify ORM method calls in table and custom commands - Verify appstash config-store usage in executor - Fix: runOrm now includes runCli so ORM is auto-enabled when CLI is enabled
- Add docs-generator.ts that produces README.md (overview, setup, commands) and COMMANDS.md (man-page style reference with synopsis, options, examples) - Wire into CLI orchestrator so docs are always generated alongside commands - Update snapshot tests: 15 tests, 10 snapshots covering all generated files
…CP, Skills)
- Add DocsConfig interface: { readme, agents, mcp, skills } with boolean flags
- Defaults: readme + agents on, mcp + skills opt-in. docs: true enables all.
- generateAgentsDocs(): structured AGENTS.md for LLM consumption with TOOL
sections, INPUT/OUTPUT schemas, WORKFLOWS, and ERROR HANDLING
- generateMcpConfig(): mcp.json with typed inputSchema per command (JSON Schema)
- generateSkills(): per-command .md skill files for agent systems
- Wire into cli/index.ts orchestrator with config-driven conditional generation
- 22 tests, 17 snapshots covering all formats and config combinations
…rget support - Move docs config to top-level GraphQLSDKConfigTarget (removed from CliConfig) - Create shared docs-utils.ts with common utilities - Add ORM docs generator (README, AGENTS.md, MCP tools, skills) - Add React Query hooks docs generator (README, AGENTS.md, MCP tools, skills) - Add per-target README and combined MCP config generators - Add root-root README for multi-target configs - Add generateMulti() to core for multi-target orchestration - Update CLI entry point to use core generateMulti() - Wire all docs generation into generate.ts - 32 tests, 31 snapshots covering all doc formats
- Add InfraNames config to CliConfig for collision detection - Add multi-target executor generator with baked endpoints and target routing - Add target-prefixed table/custom command generators - Add multi-target command map generator with target:command namespacing - Add multi-target context command with per-target endpoint prompts - Add generateAuthCommandWithName for custom auth command naming - Add resolveInfraNames() for automatic collision detection (auth->credentials, context->env) - Add generateMultiTargetCli() orchestrator - Wire into generateMulti() with unifiedCli option - Add --save-token flag on auth target custom operations - Add snapshot tests for multi-target CLI (8 new snapshots) - Add unit tests for resolveInfraNames collision detection
…, and export-schema command - Shared ephemeral DB: When multiple targets in generateMulti() share the same PGPM source, deploy once to a single ephemeral DB and reuse it across targets instead of creating N separate databases. Automatic teardown after all targets. - Multi-target cnc codegen: Add multi-target config detection to cnc codegen command, mirroring graphql-codegen CLI behavior. Supports --target flag. - Export schema from PGPM: New exportSchema()/exportSchemaSimple() functions and CLI commands (graphql-codegen export-schema, cnc export-schema) that deploy a PGPM module to an ephemeral DB, introspect via PostGraphile, and write .graphql schema files. No server required. Supports --api-names and --schemas flags.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
… flag, remove redundant commands - Add expandApiNamesToMultiTarget(): when multiple apiNames are specified, auto-expand to multi-target (each API name = separate target = separate schema) - Add --schema-only flag to cnc codegen and graphql-codegen CLIs: exports GraphQL SDL instead of running full codegen pipeline - Remove redundant cnc get-graphql-schema command (use --schema-only instead) - Remove redundant cnc export-schema command (use --schema-only instead) - Remove server/scripts/codegen-schema.ts (use --schema-only instead) - Remove graphql/codegen/src/core/export-schema.ts module
…piNamesToMultiTarget export
…redundant wrappers - Undeprecate generators/index.ts (active v5 code, not legacy v4) - Undeprecate MetaObject/QueryBuilder exports in core/index.ts - Remove deprecated formatOutput() and its test (replaced by writeGeneratedFiles) - Remove buildSchemaSDLFromDatabase() wrapper, callers use buildSchemaSDL directly - Unify camelizeArgv: camelize once at top of each CLI handler, remove dual manual-kebab + later-camelize pattern
…y cnc codegen as thin wrapper - Add expandSchemaDirToMultiTarget(): auto-discovers *.graphql files in a directory, creates one target per file named by filename - Add schemaDir config option to GraphQLSDKConfigTarget - Add --schema-dir CLI flag to both graphql-codegen and cnc codegen - Extract shared runCodegenHandler() so cnc codegen delegates to it (no more duplicated logic) - Add 13 unit tests for expandApiNamesToMultiTarget and expandSchemaDirToMultiTarget - Remove pointless camelizeArgv mock from codegen.test.ts - Simplify codegen.test.ts to verify thin wrapper delegation
…ma-only tests
- Create graphile-schema package with buildSchemaSDL (pg-env/pg-cache, deepmerge) and fetchEndpointSchemaSDL
- Update codegen imports from @constructive-io/graphql-server to graphile-schema
- Add getReadmeHeader/getReadmeFooter to docs-utils.ts with Constructive logo and disclaimer
- Update all 6 README generators to use header/footer
- Add schema-only tests covering deleted get-graphql-schema scenarios
- Update snapshot tests
- Fix require('@pgpmjs/core') -> proper ES6 import in generate.ts
…ema tests - Remove codegen:schema script from server package.json (script file was deleted) - Update CLI README to document --schema-only instead of get-graphql-schema - Update CLI help text (display.ts) to remove get-graphql-schema reference - Update CLI AGENTS.md to reflect current command structure - Add 5 unit tests for fetchEndpointSchemaSDL in graphile-schema package (live HTTP server mock, error handling, custom headers/auth)
… dep - Remove codegen and codegen:clean scripts (no codegen dir/imports exist) - Remove src/codegen/**/* from tsconfig excludes (dir doesn't exist) - Remove Codegen section from README (server is runtime-only now) - Remove rimraf devDependency (only used by deleted codegen:clean)
- Delete src/schema.ts (was just re-exporting from graphile-schema) - Remove export * from './schema' in index.ts - Remove graphile-schema dep from server (no longer needed) - Update server-test to import buildSchemaSDL from graphile-schema directly - Remove src/schema.ts from tsconfig excludes
Only packages with zero test files retain --passWithNoTests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(codegen): apiNames auto-expand to multi-target,
schemaDirexpansion,--schema-onlyflag, unified CLI handler,graphile-schemapackage, generated README headers/footersSummary
Builds on PR #729 (unified multi-target CLI architecture) with PGPM workflow improvements, a consolidation of schema export commands into one unified
--schema-onlyflag, a newschemaDirconfig option for auto-discovering.graphqlfiles, unification ofcnc codegenas a thin wrapper, a cleanup pass removing incorrect deprecations and redundant wrappers, a new lightweightgraphile-schemapackage, Constructive-branded README headers/footers for all generated documentation, and repo-wide housekeeping.Key Changes
Shared ephemeral DB for multi-target PGPM (
generate.ts):generateMulti()detects when multiple targets share the same PGPM source (sameworkspacePath+moduleNameormodulePath), deploys once to a single ephemeral DB, and reuses it. Teardown infinallyblock.Multi-target
cnc codegen(codegen.ts): Mirrors theisMultidetection fromgraphql-codegenCLI — if loaded config lacks top-levelendpoint/schemaFile/schemaDir/db, dispatches togenerateMulti(). Adds--target <name>flag.apiNamesauto-expansion to multi-target (expandApiNamesToMultiTarget()): When a config specifies multipleapiNames(e.g.['app', 'admin']), it auto-expands into a multi-target config — each API name becomes its own target with its own GraphQL schema and output directory. SingleapiNames: ['app']and explicitschemas: [...]remain single-target. Wired into both CLIs.schemaDirauto-expansion to multi-target (expandSchemaDirToMultiTarget()): New config optionschemaDirpoints to a directory of*.graphqlfiles. Each file becomes its own target, named by filename (e.g.schemas/app.graphql→ targetapp). Enables a workflow where backend devs export SDL files and frontend devs run codegen against a directory of schemas without any DB access.--schema-dirCLI flag added to both CLIs.--schema-onlyflag on bothgraphql-codegenandcnc codegen: Exports GraphQL SDL instead of running full codegen. Works with any source (endpoint, file, database, PGPM). With multi-apiNames, writes one.graphqlper API. Replaces all previous export commands.Removed redundant commands (⚠️ breaking):
cnc get-graphql-schema→ usecnc codegen --schema-onlycnc export-schema/graphql-codegen export-schema→ usecnc codegen --schema-onlygraphql/server/src/scripts/codegen-schema.ts→ usecnc codegen --schema-onlygraphql/codegen/src/core/export-schema.tsmodule removedDeprecation cleanup & camelizeArgv unification:
generators/index.ts— these are active v5 generator functions, not legacy v4MetaObject/QueryBuilderre-exports incore/index.ts— still actively usedformatOutput()and its test — truly deprecated, replaced bywriteGeneratedFileswithformatFilesoptionbuildSchemaSDLFromDatabase()passthrough wrapper — callers (DatabaseSchemaSource,PgpmModuleSchemaSource) now importbuildSchemaSDLdirectly fromgraphile-schema(see TODO #8 below)camelizeArgvflow in both CLIs: camelize once at the top of each handlerNew⚠️ Breaking:
graphile-schemapackage (graphile/graphile-schema/): Lightweight npm package containingbuildSchemaSDLandfetchEndpointSchemaSDLextracted from@constructive-io/graphql-server. Eliminates heavy server dependencies (express, cors, grafserv, middleware) from codegen. Uses properpg-env/pg-cacheutilities instead of manual connection string construction, anddeepmergefor preset object merging.@constructive-io/graphql-serverno longer exports these functions — consumers must import fromgraphile-schemadirectly.Generated README headers/footers (
docs-utils.ts): All 6 README generators (generateTargetReadme,generateRootRootReadme,generateHooksReadme,generateOrmReadme,generateReadme,generateMultiTargetReadme) now include Constructive-branded headers (centered logo + badges) and footers (credit + disclaimer). Provides consistent branding across all generated documentation.Unified
cnc codegenas thin wrapper (cli/handler.ts): Extracted sharedrunCodegenHandler()function containing all core codegen logic. Bothgraphql-codegenandcnc codegennow delegate to this shared handler after handling their own help/version flags. Eliminates ~150 lines of duplicated code. Uses structuralPrompterinterface to avoidinquirererversion mismatch between packages.Unit tests for expand functions (
expand-targets.test.ts): Added 13 unit tests coveringexpandApiNamesToMultiTargetandexpandSchemaDirToMultiTarget— null cases, single vs. multiple targets, output path defaults, config preservation, file filtering, alphabetical sorting. Removed pointlesscamelizeArgvmock fromcodegen.test.ts.--schema-onlytests (schema-only.test.ts): Added 5 unit tests coveringgenerate()withschemaOnly: true— file writing, custom filename, no generators required, error handling, directory creation.Documentation cleanup: Updated all stale references to deleted commands (
get-graphql-schema,codegen-schema,export-schema) across multiple files:graphql/server/package.json— removedcodegen,codegen:clean, andcodegen:schemascriptsgraphql/server/README.md— removed "Codegen" section (server is runtime-only now)graphql/server/tsconfig.json&tsconfig.esm.json— removedsrc/codegen/**/*andsrc/schema.tsexcludespackages/cli/README.md— replacedget-graphql-schemasection with--schema-onlydocspackages/cli/src/utils/display.ts— removedget-graphql-schemafrom help textpackages/cli/AGENTS.md— updated to reflect current command structuregraphile-schematests (fetch-endpoint-schema.test.ts): Added 5 unit tests forfetchEndpointSchemaSDLusing real HTTP mock server — live endpoint fetching, HTTP error handling, invalid JSON response, introspection errors, custom headers/auth.Server cleanup: Removed all dead codegen-related code from
@constructive-io/graphql-server:src/schema.tsbackward-compat re-export filegraphile-schemadependency (no longer needed)rimrafdevDependency (only used by deleted scripts)server-testto importbuildSchemaSDLfromgraphile-schemadirectlyTest script cleanup (41 packages): Removed
--passWithNoTestsflag from all packages that have actual test files. Only packages with zero tests retain the flag. This ensures tests actually run and fail if test files are missing or broken, rather than silently passing.Note: This PR targets
mainand includes all changes from PR #729.Updates since last revision (latest)
--passWithNoTestsfrom 41 package.json test scripts that have actual test files--passWithNoTests(correct behavior)Updates since last revision (previous)
src/schema.tsre-export from server package entirelygraphile-schemadependency from server (no runtime usage)server-testto import fromgraphile-schemadirectlycodegen,codegen:clean) from serverpackage.jsonsrc/codegen/**/*,src/schema.ts)rimrafdevDependency from servergraphile-schemapackage forfetchEndpointSchemaSDLReview & Testing Checklist for Human
@constructive-io/graphql-serverno longer exports schema functions — The server package no longer exportsbuildSchemaSDLorfetchEndpointSchemaSDL. Any external code importing these from@constructive-io/graphql-serverwill break. Migration: import fromgraphile-schemainstead. Verify no external consumers depend on these exports.buildSchemaSDLhas no unit tests ingraphile-schemapackage — WhilefetchEndpointSchemaSDLnow has 5 tests,buildSchemaSDLhas zero unit tests in the package itself. It's only tested via the integration test inserver-test/__tests__/schema-snapshot.test.tswhich requires a real database. Thepg-env/pg-cacheutilities anddeepmergepreset merging have never been tested in isolation. Verify connection string construction and preset merging work correctly.--schema-onlytests only coverschemaFilesource — The deletedget-graphql-schematests covered database mode, endpoint mode with auth/headers/headerHost options. The newschema-only.test.tsonly tests withschemaFilesource. Endpoint and database sources with auth/headers are untested. Manually verify--schema-onlyworks with endpoint and database sources.cnc get-graphql-schema,cnc export-schema,graphql-codegen export-schema,formatOutput()from@constructive-io/graphql-codegen, and schema function exports from@constructive-io/graphql-server. Any existing scripts or external consumers using these will break. Migration path: usecnc codegen --schema-onlyorgraphql-codegen --schema-onlyfor commands; usewriteGeneratedFileswithformatFiles: trueoption instead offormatOutput(); import schema functions fromgraphile-schemainstead of@constructive-io/graphql-server.pnpm buildand CI (TypeScript + unit tests) passed. All features (shared ephemeral DB, multi-target cnc, apiNames auto-expansion,schemaDirexpansion,--schema-only, unified handler,graphile-schemapackage, README headers, doc cleanup, server cleanup) need manual end-to-end testing with a real PGPM workspace and.graphqlfiles.Test Plan
buildSchemaSDLwith a real database and verify connection string construction, schema introspection, and preset merging work correctly. TestfetchEndpointSchemaSDLwith a live endpoint and auth/headers options.db: { pgpm: { ... }, apiNames: ['app', 'admin'] }. Runcnc codegenand verify two separate output directories created (./generated/graphql/app,./generated/graphql/admin) with different schemas../schemas/withapp.graphqlandadmin.graphql. Create config withschemaDir: './schemas'. Runcnc codegenand verify two targets created, each reading from its respective file.apiNames. Rungraphql-codegenand verify console shows[multi-target] Shared PGPM source deployed once for 3 targets: .... Confirm only one ephemeral DB created.--schema-onlywith PGPM: Runcnc codegen --schema-only --config <pgpm-config>and verify.graphqlfiles written to output directory. Compare SDL with previouscnc get-graphql-schemaoutput.--schema-onlywith endpoint: Runcnc codegen --schema-only --endpoint https://api.example.com/graphql --output ./schema.graphqland verify SDL written. Test with--authand--headerflags.--schema-onlywith multi-apiNames: Runcnc codegen --schema-onlywith config containingapiNames: ['app', 'admin']and verify two.graphqlfiles created (app.graphql,admin.graphql).--schema-dirCLI flag: Runcnc codegen --schema-dir ./schemas --output ./generatedand verify targets created for each.graphqlfile in the directory.graphql-codegenandcnc codegenproduce identical output for the same config (modulo help/version flags).--schema-onlyexamples).buildSchemaSDLfrom@constructive-io/graphql-serverand verify it fails with a clear error. Verify importing fromgraphile-schemaworks.pnpm testin a few of the 41 updated packages and verify tests actually run (not silently passing).Notes
schemaDirexpansion, command consolidation, unified CLI handler,graphile-schemapackage extraction, generated README branding, deprecation cleanup, documentation updates, server cleanup, and test script housekeeping. Review scope is larger than just the features listed above.komojipackage was added as a dependency (used by CLI generator).cnc codegencommand is now a thin wrapper (~48 lines) that delegates to the sharedrunCodegenHandler()function, eliminating code duplication.graphile-schemapackage usesdeepmerge@^4.3.1for preset object merging as requested by the user.fetchEndpointSchemaSDLtests importgetIntrospectionQuerybut don't use it (minor unused import).--passWithNoTestscleanup affects 41 packages. Detection was based on finding.test.ts/.test.js/.spec.tsfiles; packages with unusual test file naming/locations may have been missed (low risk).Link to Devin run: https://app.devin.ai/sessions/4bfad737a4ce4a848b01d088ad950986
Requested by: @pyramation