Skip to content

feat(codegen): add fields-with-arguments support for ORM select types#1076

Merged
pyramation merged 1 commit intomainfrom
feat/codegen-fields-with-arguments
May 9, 2026
Merged

feat(codegen): add fields-with-arguments support for ORM select types#1076
pyramation merged 1 commit intomainfrom
feat/codegen-fields-with-arguments

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

Summary

Adds support for GraphQL fields that have arguments (e.g. requestUploadUrl on bucket types) to both the introspection/codegen pipeline and the ORM runtime. Previously, the codegen treated all non-relation fields as simple boolean selects and discarded any field-level arguments from introspection data.

Introspection (graphql/query):

  • New FieldArgument interface and args?: FieldArgument[] on Field
  • extractEntityFields() now captures field arguments via extractFieldArguments() and introspectionTypeRefToTypeRef()
  • QuerySelectionOptions extended to accept { args, select } objects

Query generation (graphql/query):

  • New typeRefToGqlAstType() helper converts TypeRef → GraphQL AST type nodes
  • generateFieldSelectionsFromOptions() handles { args, select } pattern — emits field arguments as variable references and collects VariableDefinitionNodes
  • generateSelectQueryAST() merges field-arg variable definitions into the operation

Codegen (graphql/codegen):

  • buildSelectTypeLiteral() generates { args: { ... }, select?: Record<string, boolean> } for fields with arguments, with typed arg properties
  • buildSelections() runtime handles { args, select } by inlining arg values directly (via buildValueAst)
  • NestedSelectConfig and InferSelectResult updated to handle the { args, select } shape

Review & Testing Checklist for Human

  • Variable plumbing gap in select.ts: In generateFieldSelectionsFromOptions, the loop over fieldOptions.args generates $fieldName_argName variable definitions but the actual arg values (_argValue) are discarded. The buildSelect() code path will produce queries with unbound variables. Verify this path is not yet called at runtime, or add the value-collection logic.
  • Two different arg-passing strategies: select.ts uses GraphQL variables while query-builder.ts (ORM runtime) inlines values via buildValueAst. Confirm this divergence is intentional and won't cause issues when both paths are exercised.
  • Duplicate FieldArgument / Field types: The same FieldArgument interface is defined in both graphql/query/src/types/schema.ts and graphql/codegen/src/types/schema.ts. Consider whether one should re-export from the other to prevent drift.
  • End-to-end validation: Run the codegen against a schema that includes bucket types with requestUploadUrl and verify the generated Select types include the typed args object. Then exercise the ORM findMany with { args, select } to confirm the GraphQL query is well-formed.

Notes

  • No unit tests are included in this PR — the primary validation so far is that both graphql/query and graphql/codegen typecheck cleanly.
  • The select sub-property for fields-with-args is typed as Record<string, boolean> rather than a specific return-type Select — this is a pragmatic first pass since the return objects (e.g. UploadUrlPayload) are not table entities and don't get their own generated Select types.
  • Related PR: constructive-io/constructive-db#1057 removes the pnpm.overrides that were needed before the plugin was published at 0.15.0.

Link to Devin session: https://app.devin.ai/sessions/7903d2a3e7a34c6daa605e12d6b80d9e
Requested by: @pyramation

- Add FieldArgument interface and args property to Field type (both packages)
- Capture field arguments from introspection in extractEntityFields()
- Extend QuerySelectionOptions to support { args, select } pattern
- Generate typed arg properties in buildSelectTypeLiteral() for codegen
- Handle { args, select } in runtime buildSelections() (query-builder.ts)
- Add typeRefToGqlAstType helper for variable definition generation
- Wire field args through generateSelectQueryAST as variable definitions
- Update NestedSelectConfig and InferSelectResult for args+select inference
@devin-ai-integration
Copy link
Copy Markdown
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 c6e143b into main May 9, 2026
54 checks passed
@pyramation pyramation deleted the feat/codegen-fields-with-arguments branch May 9, 2026 04:04
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