Skip to content

Conversation

Tails
Copy link

@Tails Tails commented Oct 9, 2025

Fixes #498

Luuk de Waal Malefijt added 2 commits October 9, 2025 09:20
Fixes issue where GraphQL fields with leading underscores (like `_id`)
were incorrectly converted to snake_case without preserving the prefix.

Changes:
- Added `to_snake_case_preserve_leading_underscores()` helper function
- Updated all heck::to_snake_case() calls in codegen to use the wrapper
- Preserves leading underscores for:
  - Input object field names
  - Response type field names
  - Fragment names
  - Variable names
  - Module names

This fixes compatibility with TerminusDB GraphQL schema which uses
`_id` fields that should remain as `_id` in generated Rust code.

Related to: graphql-rust#498
Moved the duplicated helper function from 4 separate modules into the
shared module to eliminate code duplication.

Changes:
- Added helper to graphql_client_codegen/src/codegen/shared.rs
- Made shared module pub(crate) to allow access from generated_module.rs
- Removed duplicates from inputs.rs, selection.rs, codegen.rs, generated_module.rs
- Updated all modules to import from shared module

No functional changes, purely code organization improvement.
@tomhoule
Copy link
Member

tomhoule commented Oct 9, 2025

I enabled test runs for this PR. It looks like there are compilation errors. If this is testable, a test case or two for this fix would be helpful.

Luuk de Waal Malefijt added 2 commits October 10, 2025 00:14
After centralizing the to_snake_case_preserve_leading_underscores helper
function, several unused imports of heck traits remained in the codebase.
This commit removes those unused imports to clean up compiler warnings.

Changes:
- Removed unused ToSnakeCase import from codegen/inputs.rs
- Removed unused heck::* import from codegen/selection.rs
- Removed unused heck::ToSnakeCase import from codegen.rs
- Removed unused heck::* import from generated_module.rs
- Updated introspection test to use __schema field name instead of
  schema, correctly validating that leading underscores are preserved

All tests pass: cargo test --all --tests --examples
Apply rustfmt formatting to all files to comply with project style guidelines.
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.

Field renaming causing collisions with names like "_id"

2 participants