Skip to content

fix: align filter input type name casing for index and relational query fields - #3525

Open
sharonyajain wants to merge 1 commit into
mainfrom
fix/gsi-relational-filter-input-casing-3267
Open

fix: align filter input type name casing for index and relational query fields#3525
sharonyajain wants to merge 1 commit into
mainfrom
fix/gsi-relational-filter-input-casing-3267

Conversation

@sharonyajain

Copy link
Copy Markdown
Contributor

Description of changes

Amplify Data models whose GraphQL type name does not begin with an uppercase letter (e.g. a model declared as userPrivateSyncItem) produce a schema whose secondary-index (@index queryField) and @hasMany connection query fields declare a filter argument type that the generated client never sends. At runtime AppSync rejects the query with:

Validation error of type VariableTypeMismatch: Variable type 'ModelUserPrivateSyncItemFilterInput'
doesn't match expected type 'ModeluserPrivateSyncItemFilterInput' @ 'userPrivateSyncItemsByDataType'

Root cause: two helpers name the Model<name>FilterInput type with different casing rules:

  • The model transformer (regular list query) uses getFilterInputNametoPascalCase(['Model', name, 'FilterInput']), which capitalizes the model name → ModelUserPrivateSyncItemFilterInput.
  • The index transformer (GSI query field) and the relational transformer (@hasMany connection field) used ModelResourceIDs.ModelFilterInputTypeName(name), which is a raw `Model${name}FilterInput` with no capitalization → ModeluserPrivateSyncItemFilterInput.

The generated client (@aws-amplify/data-schema) PascalCases the model name, matching the model transformer. So for a lowercase-first model name the base list filter type matches the client, but the GSI / @hasMany filter type does not — hence the mismatch on those fields only.

Fix: align the index and relational transformers to the same getFilterInputName helper the model transformer uses, so the filter input type name is generated consistently.

  • packages/amplify-graphql-index-transformer/src/schema.ts
    • makeModelXFilterInputObject now creates the filter input type via getFilterInputName(object.name.value).
    • ensureQueryField aligns the GSI query field's filter argument type to the same name.
  • packages/amplify-graphql-relational-transformer/src/schema.ts
    • makeModelConnectionField and makeModelXFilterInputObject now use getFilterInputName(relatedType.name.value).

For model names that already start with an uppercase letter, getFilterInputName returns a string identical to the previous ModelResourceIDs.ModelFilterInputTypeName output, so there is no change for the common case (confirmed by unchanged snapshots). The shared ModelResourceIDs.ModelFilterInputTypeName helper is intentionally left untouched, since it is used by other code paths; only the two affected transformers are changed.

CDK / CloudFormation Parameters Changed

None. This only changes a generated GraphQL type name (and only for model names that do not begin with an uppercase letter).

Issue #, if available

Fixes aws-amplify/amplify-backend#3267

Description of how you validated changes

  • Added regression unit tests using a lowercase-first model name:
    • amplify-graphql-index-transformer.test.ts — asserts the GSI query field and the list query field both reference ModelUserPrivateSyncItemFilterInput, and no ModeluserPrivateSyncItemFilterInput type is emitted.
    • amplify-graphql-has-many-transformer.test.ts — asserts the @hasMany connection field's filter arg is ModelOtherPartFilterInput (related model otherPart), and no lowercase variant is emitted.
  • yarn build + yarn test on both affected packages:
    • index transformer: 94/94 tests, 30/30 snapshots pass (no snapshot churn).
    • relational transformer: 195/195 tests, 126/126 snapshots pass (no snapshot churn).
  • Ran eslint on the four changed files: no new lint findings introduced by this change. Pre-existing lint issues in these files (jsdoc, no-shadow, max-depth, function length, etc.) are unrelated to this fix and left as-is per the repo's iterative-lint policy.
  • Not validated against a live AppSync deployment; verification is at the transformer/schema level.

Checklist

  • PR description included
  • yarn test passes (for the two affected packages)
  • E2E test run linked
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced) — n/a
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies — n/a
  • Any CDK or CloudFormation parameter changes are called out explicitly (none)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…ry fields

The GSI (@index queryField) and @hasmany connection query fields named their
`Model<name>FilterInput` argument type with the model name verbatim (via
ModelResourceIDs.ModelFilterInputTypeName), while the model transformer and the
generated client use the PascalCased getFilterInputName. For models whose names
do not start with an uppercase letter these diverge, so AppSync rejects the
client query with a VariableTypeMismatch (e.g. ModelUserPrivateSyncItemFilterInput
vs ModeluserPrivateSyncItemFilterInput).

Align both transformers to getFilterInputName so the generated schema matches the
client. PascalCase model names are unaffected (identical output; no snapshot churn).

Fixes aws-amplify/amplify-backend#3267
@sharonyajain
sharonyajain requested a review from a team as a code owner August 24, 2026 21:24
@sharonyajain
sharonyajain requested a review from Simone319 August 24, 2026 22:21
@sharonyajain sharonyajain self-assigned this Aug 25, 2026
@Simone319

Copy link
Copy Markdown
Contributor

Approved if the e2e tests succeeds.

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.

The data GSI create mismatch variable name

2 participants