feat(graphql-transformer): warn on unused stackMappings keys during s…#3486
Merged
Conversation
|
|
||
| const unusedKeys = Object.keys(this.stackMappingOverrides).filter((key) => !seenMappingKeys.has(key)); | ||
| if (unusedKeys.length > 0) { | ||
| console.warn( |
Member
There was a problem hiding this comment.
Should we use this.logs.push() here?
Contributor
Author
There was a problem hiding this comment.
Yes, updated to use this.logs.push().
bff55c6 to
2e73ed5
Compare
adrianjoshua-strutt
approved these changes
May 19, 2026
svidgen
approved these changes
May 19, 2026
2e73ed5 to
9f86f2c
Compare
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
Adds synthesis-time validation for
stackMappingskeys. When a user provides mapping keys that don't match any generated resolver, a warning is emitted duringcdk synth(before deployment).Problem
Invalid
stackMappingskeys (typos or stale entries after renaming a model) are silently ignored — the resolver falls back to its default stack with zero feedback. Users have no way to know their mapping isn't taking effect.Solution
During the existing resolver collection phase in
GraphQLTransform.collectResolvers(), track whichstackMappingskeys match a generated resolver's logical ID. After the loop, warn on any unmatched keys:This is a warning (not an error) to maintain backward compatibility with existing users who may have stale keys.
Changes
packages/amplify-graphql-transformer-core/src/transformation/transform.tscollectResolvers()loop +console.warnpackages/amplify-graphql-transformer-core/src/transformer-context/resolver.tsresolverLogicalIdpublic readonly (needed for validation access)packages/amplify-graphql-transformer/src/__tests__/stack-mappings-validation.test.tsHow it works
Integrated into the existing
collectResolvers()loop (single pass, no extra iteration):Design decisions
@aws-amplify/graphql-api-constructmay have stale keys. Throwing would break them on upgrade.transform.tsusing collected resolvers, keepingStackManagerclean (single responsibility).Testing
Companion PR
This validation works alongside the
stackMappingsexposure PR inamplify-backend: feat/stack-mappingsChecklist