fix(graphql-codegen-client-preset): respect namingConvention config#593
fix(graphql-codegen-client-preset): respect namingConvention config#593
Conversation
Add `namingConvention` option to the SWC plugin to match the naming convention configured in codegen.ts. The default is now `change-case-all#pascalCase` (matching graphql-codegen's client-preset default), which correctly handles word boundaries in names like `SomeEGRockets` → `SomeEgRocketsDocument`. Previously, the plugin used `upperCaseFirst` behavior (only capitalize first letter), causing mismatches when operation names contained consecutive uppercase letters like `SomeEGRockets`. Fixes #521 Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
|
|
|
Code ReviewThanks for this fix! The issue is real and the approach is generally sound. Here's my feedback: Positive changes
Concerns1. Missing changeset The changeset bot flagged this. This is a breaking change in default behavior — the default naming convention is changing from 2. Silent fallback for unrecognized conventions fn apply_naming_convention(s: &str, naming_convention: &str) -> String {
match naming_convention {
"change-case-all#upperCaseFirst" => upper_case_first(s),
_ => to_pascal_case(s), // ← silently handles unknown conventions
}
}If a user sets 3. Re-implementing Rather than re-implementing the pascal case algorithm, have you considered depending on the 4. Limited convention support not documented The README only mentions 5. Edge cases in The function handles these correctly on inspection, but tests would make this more robust:
6. Minor: unnecessary let import_name = apply_naming_convention(&operation_name, &self.options.naming_convention);
self.graphql_operations_or_fragments_to_import.push(import_name.clone());
let new_expr = Expr::Ident(quote_ident!(import_name).into());The SummaryThe core fix is correct and needed. The main action items before merging:
Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 332e70f974
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fn apply_naming_convention(s: &str, naming_convention: &str) -> String { | ||
| match naming_convention { | ||
| "change-case-all#upperCaseFirst" => upper_case_first(s), | ||
| _ => to_pascal_case(s), |
There was a problem hiding this comment.
Handle non-pascal
namingConvention values instead of forcing PascalCase
apply_naming_convention only recognizes change-case-all#upperCaseFirst; every other string falls through to to_pascal_case. GraphQL Code Generator also accepts values like keep, change-case-all#lowerCase, lodash#camelCase, or a custom module path, so projects that mirror one of those valid configs into this plugin will still import PascalCased symbols. For example, with namingConvention: "keep", an operation like SomeEGRockets should stay SomeEGRocketsDocument, but this transform rewrites it to SomeEgRocketsDocument, which no longer matches the generated export.
Useful? React with 👍 / 👎.
| #[serde(default = "naming_convention_default")] | ||
| namingConvention: String, |
There was a problem hiding this comment.
Accept object-form
namingConvention configs
PluginOptions now deserializes namingConvention as a plain String, but valid Codegen configs also use the object form (for example to set enumValues separately or enable transformUnderscore). If a project follows the new README guidance and passes that same config into the SWC plugin, serde_json::from_str(...).expect(...) in process_transform will reject the object and abort the transform before compilation starts.
Useful? React with 👍 / 👎.
## Summary - Addressed `chatgpt-codex-connector[bot]` review follow-ups across merged PRs: #585, #591, #592, #593, #594, #595, #597, #598, #599. - Applied the fixes as 9 separate commits (one commit per original PR) in a single follow-up branch. ## What Changed - #585 / #592 (`loadable-components`) - Fixed source-less default-import matching to honor the configured local name. - Updated `ssr: false` detection to respect final object-literal override order. - Added/updated fixtures for both behaviors. - #591 / #594 (`formatjs`) - Added JSX member-expression message component support (e.g. `ReactIntl.FormattedMessage`). - Updated #532 regression coverage to validate the `ast: true` path. - #593 / #595 (`graphql-codegen-client-preset`) - Extended `namingConvention` parsing to accept string/object forms. - Preserved names for `keep`/unknown conventions instead of forcing PascalCase. - Fixed Windows absolute `filename` path handling in WASM runtime path resolution. - Added unit coverage for the new config/path behaviors. - #597 / #599 (`emotion`) - Ensured tagged-template labels are terminated before sourcemap comments. - Added css-prop rewrite support for namespace imports (`emotionReact.css`). - Attached PURE comments to the generated call site span. - Updated emotion fixtures accordingly. - #598 (docs) - Corrected capability descriptions in `packages/jest/README.tmpl.md` and `packages/swc-sdk/README.tmpl.md`. ## Validation - `cargo test -p swc_plugin_loadable_components --test fixture -- --ignored` - `cargo test -p swc_plugin_graphql_codegen_client_preset` - `cargo test -p swc_emotion --test fixture -- --ignored` - `pnpm -C /Users/kdy1/.codex/worktrees/17e6/plugins/packages/formatjs test` All passed (formatjs has an existing non-blocking Vitest warning about an un-awaited rejects assertion).
Fixes #521
Add
namingConventionoption to the SWC plugin to match the naming convention configured in codegen.ts. The default is nowchange-case-all#pascalCase(matching graphql-codegen's client-preset default), which correctly handles word boundaries in names likeSomeEGRockets→SomeEgRocketsDocument.Previously, the plugin used
upperCaseFirstbehavior (only capitalize first letter), causing mismatches when operation names contained consecutive uppercase letters.Generated with Claude Code