fix(cli-internal): use consistent model name casing for DynamoDB table references - #14892
Merged
Conversation
…e references Extract model names from the GraphQL schema and use case-insensitive matching when resolving table names from environment variable names. This fixes incorrect capitalization for non-PascalCase models (e.g., 'randomItem' was incorrectly becoming 'Randomitem'). --- Prompt: Fix non-PascalCase model name resolution in gen2-migration function generator by reading model names from the GraphQL schema and matching case-insensitively.
adrianjoshua-strutt
force-pushed
the
fix/non-pascal-case-model-14561
branch
from
May 18, 2026 20:58
d559b48 to
d0f114f
Compare
soberm
previously approved these changes
May 19, 2026
sarayev
previously approved these changes
May 19, 2026
…hemaModelNames The original readSchemaModelNames() only read schema.graphql (single file) and used a fragile regex that fails when directives appear between the type name and @model (e.g., @auth(rules: [{...}]) @model). This commit: - Uses build/schema.graphql with ModelXConnection regex as the primary approach (matching createTableMappings pattern from DataGenerator). - Falls back to raw user schema when build schema is unavailable, supporting both single schema.graphql AND schema/*.graphql directory patterns (matching collectUserSchema from DataGenerator). - Replaces the fragile regex with a parenthesis-depth-aware parser that correctly handles directives with nested braces before @model. Adds tests for: build schema primary path, raw schema fallback, multiple directives before @model, schema directory pattern, and no-API case.
adrianjoshua-strutt
requested review from
sarayev and
soberm
and removed request for
soberm
May 26, 2026 14:45
sarayev
previously approved these changes
May 26, 2026
sharonyajain
previously approved these changes
Aug 18, 2026
soberm
previously approved these changes
Aug 25, 2026
adrianjoshua-strutt
dismissed
soberm’s stale review
August 25, 2026 09:04
The merge-base changed after approval.
soberm
previously approved these changes
Aug 25, 2026
sharonyajain
previously approved these changes
Aug 25, 2026
adrianjoshua-strutt
dismissed stale reviews from sharonyajain and soberm
August 25, 2026 09:09
The merge-base changed after approval.
soberm
previously approved these changes
Aug 25, 2026
sharonyajain
previously approved these changes
Aug 25, 2026
sharonyajain
requested review from
a team and
sarayev
and removed request for
sarayev
August 25, 2026 09:17
sarayev
reviewed
Aug 25, 2026
…ution - Merge build-schema and raw-schema model names instead of returning early, so models declared @model(queries: null) (no ModelXConnection type) are not missed and fall through to naive casing. - extractTableName: match known model names directly against the env var to handle underscore-containing names; anchor the naive fallback regex to the last segment before TABLE_; document the case-insensitive collision assumption. - Harden @model detection with a word boundary so @models/@modelFoo no longer match. - Tighten the naive-fallback test to assert the exact generated table reference, and add extractTableName unit tests plus a queries:null merge regression test.
sarayev
reviewed
Aug 26, 2026
- bound the raw-schema @model scan to each type so a bodyless type cannot leak into the next (defense-in-depth) - document the single-file-XOR-directory schema invariant in collectUserSchema - emit printer.debug in the two schema-read catch blocks to aid diagnosing a miscased table - add a guard test that a non-model type preceding real models is never attributed as a table
sarayev
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a GraphQL model uses non-PascalCase naming (e.g.,
randomItem), the generated code previously used naive capitalization to reconstruct the model name from the uppercase environment variable (API_MYAPI_RANDOMITEMTABLE_ARN→Randomitem). This caused deployment failures becausebackend.data.resources.tablesis keyed by the original model name from the schema.Root Cause
The
extractTableNamefunction appliedcharAt(0).toUpperCase() + slice(1).toLowerCase()to the captured segment from the env var name. Since Gen1 uppercases model names in env vars, this transformation cannot reconstruct names likerandomItemorMealPlan— it producesRandomitemandMealplaninstead.Fix
The fix reads model names from the GraphQL schema (using the same regex pattern already used by
DataGenerator) and performs a case-insensitive lookup to recover the original casing. Both the environment variable escape hatches and the table grant statements now consistently use the correct model name.The lookup is cached per
FunctionGeneratorinstance to avoid redundant schema reads.Testing
randomItemandMealPlanmodels to verify correct casing in generated outputgen2-migration/generatecontinue to passFixes #14561