feat: add overriden and extended resolver support#14795
Open
dgandhi62 wants to merge 29 commits intogen2-migrationfrom
Open
feat: add overriden and extended resolver support#14795dgandhi62 wants to merge 29 commits intogen2-migrationfrom
dgandhi62 wants to merge 29 commits intogen2-migrationfrom
Conversation
…lvers When a Gen1 project has custom VTL resolver files in amplify/backend/api/<name>/resolvers/, the DataGenerator now: - Detects .vtl files in the local resolvers directory - Copies them to amplify/data/resolvers/ in the Gen2 output - Generates backend.ts code that reads the VTL files at runtime and overrides pipeline function request/response mapping templates, replacing S3-based templates with inline content Supports both .req.vtl (request) and .res.vtl (response) resolver overrides. The generated for-of loop determines the resolver type from the filename suffix and overrides the corresponding mapping template properties.
…lvers When a Gen1 project has custom VTL resolver files in amplify/backend/api/<name>/resolvers/, the DataGenerator now: - Detects .vtl files in the local resolvers directory - Copies them to amplify/data/resolvers/ in the Gen2 output - Generates backend.ts code that reads the VTL files at runtime and overrides pipeline function request/response mapping templates, replacing S3-based templates with inline content Supports both .req.vtl (request) and .res.vtl (response) resolver overrides. The generated for-of loop determines the resolver type from the filename suffix and overrides the corresponding mapping template properties. Added 6 unit tests covering: no resolvers directory, empty directory, VTL file detection, file copying, backend.ts contributions, and mixed req/res file handling. All 20 tests pass. --- Prompt: A while ago, we refactored our gen2-migration code to a new structure. The following is a pr from the old structure. I need to replicate the same functionality - 14624
38d30a8 to
b11c053
Compare
d6aedf0 to
62fe0b4
Compare
d89daad to
62fe0b4
Compare
…fy-cli into extend-default-resolvers # Conflicts: # amplify-migration-apps/mood-board/_snapshot.post.generate/amplify/backend.ts
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.
How extended resolvers work
In Gen1, extended resolvers are VTL files with 6-segment filenames like
Mutation.createBoard.init.2.req.vtl. The segments encode the target resolver (Mutation.createBoard), the pipeline slot (init), the execution order within that slot (2), and the template type (req). Gen1 places these as separate pipeline functions at the appropriate slot position.In Gen2, we recreate this by generating
AppsyncFunctionconstructs with aNoneDataSourceand splicing them into the existing pipeline resolver's function array at the correct position.Type-specific slot mapping
Different GraphQL operation types have different valid slots and different default pipeline structures:
[auth0, postAuth0, DataResolverFn]— slots includepreDataLoad/postDataLoad[init0, auth0, postAuth0, DataResolverFn]— slots includepreUpdate/postUpdate[auth0, postAuth0, DataResolverFn]— same slots as create/update but shorter default pipeline[auth0, postAuth0, DataResolverFn]— slots includepreSubscribeThe splice index computation accounts for these differences by selecting the correct base index mapping based on the operation type and field name prefix.
Override resolver filter fix
The generated override resolver loop previously matched all
.req.vtl/.res.vtlfiles regardless of segment count. This caused 6-segment extended resolver files to be incorrectly applied as DataResolverFn template overrides. The filter now includes af.split(".").length === 4guard to only process 4-segment override files.Splice index computation algorithm
The algorithm places custom functions into the Gen2 pipeline at positions that match their Gen1 slot behavior. It works in three steps:
1. Determine the default pipeline shape. The base indexes depend on which default functions exist:
Each slot maps to a base index — the position after the last default function for that slot:
2. Sort custom functions. Functions are sorted by slot (pipeline execution order), then by numeric order within the same slot. The order number in the filename only determines relative ordering among custom functions in the same slot — it does not map to an absolute pipeline position.
3. Compute splice indexes with a running offset. Walk through the sorted functions in order. For each function:
The offset accounts for prior insertions shifting subsequent positions. Example with
init.2andfinish.1on a create mutation:Checklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.