Skip to content

Comments

fix(codegen): upstream CLI fixes - no-arg query, field defaults, NodeHttpAdapter as top-level option#737

Merged
pyramation merged 5 commits intomainfrom
devin/1771925145-codegen-upstream-fixes
Feb 24, 2026
Merged

fix(codegen): upstream CLI fixes - no-arg query, field defaults, NodeHttpAdapter as top-level option#737
pyramation merged 5 commits intomainfrom
devin/1771925145-codegen-upstream-fixes

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Feb 24, 2026

fix(codegen): upstream CLI fixes — no-arg queries, field defaults, NodeHttpAdapter as top-level option

Summary

Three upstream codegen fixes that eliminate workarounds previously needed in the bash CLI e2e test script. These are bugs discovered during CLI end-to-end testing in constructive-hub.

1. No-arg query call signature (custom-command-generator.ts)

Queries with zero arguments (e.g. currentUser) generated .currentUser({}, { select }) — an extraneous empty args object. The ORM expects .currentUser({ select }). Fixed by adding a hasArgs flag to buildOrmCustomCall that omits the empty args when the operation has no arguments.

2. Fields with defaults marked not-required (table-command-generator.ts)

All create-mutation fields were marked required: true regardless of whether they have database defaults or are trigger-populated. New getFieldsWithDefaults() looks up the CreateXInput type in the TypeRegistry (from introspection) and checks each inner field's defaultValue and nullability. Fields with defaults or nullable types are now required: false.

3. NodeHttpAdapter — elevated to top-level generation option

NodeHttpAdapter (in templates/node-fetch.ts) implements the GraphQLAdapter interface using node:http/node:https directly — no global patching.

What changed since last revision: nodeHttpAdapter was moved from CliConfig to GraphQLSDKConfigTarget so it's available to any generator (ORM, CLI, or custom Node.js apps), not just CLI.

New behavior:

  • nodeHttpAdapter: true on the top-level config generates node-fetch.ts in the ORM output directory and re-exports NodeHttpAdapter from the ORM index
  • When CLI is enabled (cli: true), nodeHttpAdapter is auto-enabled unless explicitly set to false
  • A developer building a Node.js app can use it without CLI:
    import { createClient, NodeHttpAdapter } from './generated/graphql/orm';
    const db = createClient({
      adapter: new NodeHttpAdapter('http://auth.localhost:3000/graphql', headers),
    });

Updates since last revision

  • Elevated nodeHttpAdapter from CliConfig to GraphQLSDKConfigTarget — now usable by ORM and any Node.js application, not just CLI
  • Auto-enable for CLI: When cli: true, nodeHttpAdapter is automatically enabled unless nodeHttpAdapter: false is explicitly set
  • ORM integration: When enabled, node-fetch.ts is generated into orm/ and NodeHttpAdapter is re-exported from the ORM index.ts
  • Multi-target support: generateMulti passes nodeHttpAdapter through to the unified CLI generator (defaults to enabled)
  • Template comment: Updated from "for CLI" to "for Node.js applications"

Review & Testing Checklist for Human

  • Auto-enable default for CLI: When cli: true is set without mentioning nodeHttpAdapter, the adapter is now auto-generated. Verify this doesn't break any existing downstream configs that don't expect a node-fetch.ts in their output. The snapshot tests pass, but they may not cover configs with cli: true that were generated before this change.
  • ORM standalone usage: Generate an ORM with orm: true, nodeHttpAdapter: true (no CLI) and verify import { NodeHttpAdapter } from './orm' works correctly. The re-export depends on the file being generated — if the generation logic has a bug, the import will fail.
  • Multi-target auto-enable: In generateMulti, nodeHttpAdapter defaults to true unless the first target explicitly sets nodeHttpAdapter: false. This could be surprising if users expect opt-in behavior. Test a multi-target config to verify the default is acceptable.
  • @constructive-io/graphql-types dependency: node-fetch.ts template imports GraphQLAdapter, GraphQLError, QueryResult from @constructive-io/graphql-types. Confirm generated ORM projects (not just CLI) always have this dependency available.

Notes

  • All 301 codegen tests pass (snapshots included).
  • pnpm build succeeds across all packages.
  • The one CI failure (packages/csv-to-pg) is a minio container port conflict — unrelated to these changes.
  • Fix readme #2 is backward compatible: if typeRegistry is not provided, behavior is unchanged (all fields remain required: true for create).
  • The generateNodeFetchFile utility is imported dynamically from ./codegen/cli/utils-generator in generate.ts when generating ORM output. This is a minor code organization coupling but not a functional issue.

Link to Devin run: https://app.devin.ai/sessions/d41228699b3a46de9e73cc13dda02882
Requested by: @pyramation

…ults, localhost adapter

1. Fix query call signature for no-arg queries (e.g. currentUser)
   - buildOrmCustomCall now skips empty args object and passes {select} as single param
   - Fixes: .currentUser({}, {select}) -> .currentUser({select})

2. Mark fields with defaults as not-required in create operations
   - Uses TypeRegistry to look up CREATE input type's defaultValue from introspection
   - Fields with defaults or nullable types are marked required: false
   - Passed via new typeRegistry option on TableCommandOptions

3. Add localhost fetch adapter for *.localhost subdomain routing
   - New template: localhost-fetch.ts patches globalThis.fetch using node:http.request
   - Enables local dev with subdomain routing (e.g. auth.localhost:3000)
   - Configurable via cli.localhostAdapter option in CliConfig
   - Auto-imported in executor when enabled
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

unknown added 3 commits February 24, 2026 10:22
Replaces the localhost-fetch.ts global monkey-patch with a clean
NodeHttpAdapter class that implements GraphQLAdapter using node:http/https.

- No global patching of globalThis.fetch
- NodeHttpAdapter handles *.localhost DNS + Host header internally
- Executor passes adapter to createClient instead of side-effect import
- Follows same pattern as FetchAdapter in orm-client.ts
- Follows same http.request pattern as fetch-schema.ts
@devin-ai-integration devin-ai-integration bot changed the title fix(codegen): upstream CLI fixes - no-arg query signature, field defaults, localhost adapter fix(codegen): upstream CLI fixes - no-arg query signature, field defaults, node http adapter Feb 24, 2026
…tion

- Move nodeHttpAdapter from CliConfig to GraphQLSDKConfigTarget
- Auto-enable nodeHttpAdapter when CLI generation is enabled (unless explicitly false)
- Generate node-fetch.ts in ORM output when nodeHttpAdapter is enabled
- Export NodeHttpAdapter from ORM index.ts for standalone Node.js usage
- Pass nodeHttpAdapter to multi-target CLI generator
- Update template comment to reflect general Node.js usage (not CLI-specific)

This allows any Node.js application (ORM, CLI, or custom) to use NodeHttpAdapter
for localhost subdomain routing without needing CLI generation enabled.
@devin-ai-integration devin-ai-integration bot changed the title fix(codegen): upstream CLI fixes - no-arg query signature, field defaults, node http adapter fix(codegen): upstream CLI fixes - no-arg query, field defaults, NodeHttpAdapter as top-level option Feb 24, 2026
@pyramation pyramation merged commit 5665daa into main Feb 24, 2026
44 checks passed
@pyramation pyramation deleted the devin/1771925145-codegen-upstream-fixes branch February 24, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant