fix(cli-internal): use consistent model name casing for DynamoDB table references#14892
Open
adrianjoshua-strutt wants to merge 2 commits into
Open
fix(cli-internal): use consistent model name casing for DynamoDB table references#14892adrianjoshua-strutt wants to merge 2 commits into
adrianjoshua-strutt wants to merge 2 commits into
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.
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.
sarayev
approved these changes
May 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