Skip to content

feat(gen2-migration): add migration support for overriding default reso…#14761

Closed
dgandhi62 wants to merge 12 commits intogen2-migrationfrom
override-default-resolvers
Closed

feat(gen2-migration): add migration support for overriding default reso…#14761
dgandhi62 wants to merge 12 commits intogen2-migrationfrom
override-default-resolvers

Conversation

@dgandhi62
Copy link
Copy Markdown
Contributor

@dgandhi62 dgandhi62 commented Apr 8, 2026

When a Gen1 project has custom VTL resolver files in amplify/backend/api/<name>/resolvers/, the migration tool now detects them, copies them to amplify/data/resolvers/ in the Gen2 output, and generates backend.ts code that overrides the pipeline function mapping templates at runtime.

Gen1 and Gen2 both use pipeline resolvers. The generated code reads VTL files from data/resolvers/, looks up the corresponding cfnFunctionConfigurations entry by convention (${typeName}${FieldName}DataResolverFn), clears the S3 template location, and sets the inline template content instead. Both request (.req.vtl) and response (.res.vtl) overrides are supported.

EXPECTED OUTPUT

import * as assets from 'aws-cdk-lib/aws-s3-assets'
const __dirname = dirname(fileURLToPath(import.meta.url));
const resolversDir = join(__dirname, 'data/resolvers');
const resolverFiles = readdirSync(resolversDir).filter(
  (f) => f.endsWith('.req.vtl') || f.endsWith('.res.vtl')
);
for (const file of resolverFiles) {
  const parts = file.replace('.req.vtl', '').replace('.res.vtl', '').split('.');
  const [typeName, fieldName] = parts;
  const isRequest = file.endsWith('.req.vtl');
  const functionId = `${typeName}${
    fieldName.charAt(0).toUpperCase() + fieldName.slice(1)
  }DataResolverFn`;
  const pipelineFunction =
    backend.data.resources.cfnResources.cfnFunctionConfigurations[functionId];
  if (pipelineFunction) {
    const templatePath = join(resolversDir, file);
    const vtlTemplate = new assets.Asset(backend.data.stack, `VTLTemplate-${file}`, {
      path: templatePath
    });
    if (isRequest) {
      pipelineFunction.requestMappingTemplateS3Location = vtlTemplate.s3ObjectUrl;
    } else {
      pipelineFunction.responseMappingTemplateS3Location = vtlTemplate.s3ObjectUrl;
    }
  }
}

Along with a copied resolvers directory

…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.
@dgandhi62 dgandhi62 requested a review from a team as a code owner April 8, 2026 15:09
@dgandhi62 dgandhi62 marked this pull request as draft April 8, 2026 15:09
@dgandhi62 dgandhi62 changed the title feat(cli-internal): add migration support for overriding default reso… feat(gen2-migration): add migration support for overriding default reso… Apr 9, 2026
@dgandhi62 dgandhi62 closed this Apr 9, 2026
@dgandhi62 dgandhi62 deleted the override-default-resolvers branch April 9, 2026 21:30
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.

1 participant