Skip to content

fix(cli-internal): use consistent model name casing for DynamoDB table references#14892

Open
adrianjoshua-strutt wants to merge 2 commits into
devfrom
fix/non-pascal-case-model-14561
Open

fix(cli-internal): use consistent model name casing for DynamoDB table references#14892
adrianjoshua-strutt wants to merge 2 commits into
devfrom
fix/non-pascal-case-model-14561

Conversation

@adrianjoshua-strutt
Copy link
Copy Markdown
Member

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_ARNRandomitem). This caused deployment failures because backend.data.resources.tables is keyed by the original model name from the schema.

Root Cause

The extractTableName function applied charAt(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 like randomItem or MealPlan — it produces Randomitem and Mealplan instead.

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 FunctionGenerator instance to avoid redundant schema reads.

Testing

  • Added a test exercising randomItem and MealPlan models to verify correct casing in generated output
  • All 242 existing tests in gen2-migration/generate continue to pass

Fixes #14561

@adrianjoshua-strutt adrianjoshua-strutt marked this pull request as ready for review May 18, 2026 17:10
@adrianjoshua-strutt adrianjoshua-strutt requested a review from a team as a code owner May 18, 2026 17:10
@adrianjoshua-strutt adrianjoshua-strutt changed the base branch from gen2-migration to dev May 18, 2026 17:40
…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 adrianjoshua-strutt force-pushed the fix/non-pascal-case-model-14561 branch from d559b48 to d0f114f Compare May 18, 2026 20:58
soberm
soberm previously approved these changes May 19, 2026
sarayev
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 adrianjoshua-strutt dismissed stale reviews from sarayev and soberm via 84b0c74 May 19, 2026 09:31
@adrianjoshua-strutt adrianjoshua-strutt self-assigned this May 19, 2026
@adrianjoshua-strutt adrianjoshua-strutt requested review from sarayev and soberm and removed request for soberm May 26, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(gen2-migration) generate command creates incorrect env variable declaration for a function that accesses a non pascal cased model name table

3 participants