Skip to content

Comments

feat(codegen): add --select flag to custom CLI commands using nested-obj#735

Merged
pyramation merged 1 commit intomainfrom
devin/1771844479-select-flag-custom-commands
Feb 23, 2026
Merged

feat(codegen): add --select flag to custom CLI commands using nested-obj#735
pyramation merged 1 commit intomainfrom
devin/1771844479-select-flag-custom-commands

Conversation

@pyramation
Copy link
Contributor

feat(codegen): add --select flag to custom CLI commands using nested-obj

Summary

Replaces the hardcoded buildSelectObject() in custom-command-generator.ts — which baked field selections into generated code at codegen time (and only selected clientMutationId for mutations) — with a runtime --select flag.

Generated commands now accept:

cli auth:sign-up --input '...' --select 'clientMutationId,result.accessToken,result.userId'

The buildSelectFromPaths() runtime helper (added to cli-utils.ts template) parses the comma-separated dot-notation string into the nested { select: { ... } } structure the ORM expects:

{ clientMutationId: true, result: { select: { accessToken: true, userId: true } } }

Key changes:

  • cli-utils.ts template: New buildSelectFromPaths() function using nested-obj for dot-notation parsing
  • custom-command-generator.ts: Removed buildSelectObject(), added hasObjectReturnType() and buildDefaultSelectString(). For OBJECT return types, generates buildSelectFromPaths(argv.select ?? 'defaultFields'). For scalar return types, skips select entirely.
  • Snapshots: 3 updated to reflect the new pattern

Review & Testing Checklist for Human

  • nested-obj dependency gap: The cli-utils.ts template now imports nested-obj, but there is no mechanism to auto-add it to the generated CLI's package.json. Consumers will need to manually pnpm add nested-obj after regenerating. Verify this is acceptable or if infra-generator.ts / docs should be updated to surface this requirement.
  • Empty default select for queries: currentUser (a query with no known fields) defaults to buildSelectFromPaths("") which produces {}. Verify the ORM handles { select: {} } gracefully — or should queries without known return fields skip select entirely (like scalar return types)?
  • buildSelectFromPaths correctness: No dedicated unit tests for the function. Manually verify nested path handling (e.g. 'a.b.c,a.b.d' should merge correctly into { a: { select: { b: { select: { c: true, d: true } } } } }). The objectPath.set() usage is only for leaf assignment — intermediate nesting is manual.
  • Regenerate constructive-db CLI after publishing to verify the generated code works end-to-end with real mutations like signUp.

Notes

Replace hardcoded buildSelectObject() with runtime --select flag for
custom mutation/query commands. When return type is OBJECT, generated
commands now accept --select 'field1,field2.nested' which uses
buildSelectFromPaths() (powered by nested-obj) to build the proper
nested { select: { ... } } structure at runtime.

- Add buildSelectFromPaths() to cli-utils.ts template
- Import nested-obj for dot-notation path parsing
- Remove hardcoded buildSelectObject() from custom-command-generator
- Add hasObjectReturnType() and buildDefaultSelectString() helpers
- For OBJECT return types: generate runtime select via --select flag
- For scalar return types: skip select entirely (no change needed)
- Default select falls back to all top-level fields when --select omitted
- Update 3 snapshots to reflect new generated code pattern
@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

@pyramation pyramation merged commit 2c9f7c9 into main Feb 23, 2026
44 checks passed
@pyramation pyramation deleted the devin/1771844479-select-flag-custom-commands branch February 23, 2026 11:10
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