Skip to content

gen2-migration "generate" emits uncompilable data resource — schema.graphql embedded in a TS template literal without escaping (backticks / @ in docstrings) #14913

Description

@rayelward

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

20.19.6

Amplify CLI Version

@aws-amplify/cli-internal-gen2-migration-experimental-alpha@0.7.0 (host @aws-amplify/cli 14.3.0) — bug is in the experimental gen2-migration alpha, not the core CLI

What operating system are you using?

macOS

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual cloud changes. The docstring containing the backtick / @ is committed in our schema.graphql.

Describe the bug

When amplify gen2-migration generate (@aws-amplify/cli-internal-gen2-migration-experimental-alpha@0.7.0) renders the Gen 2 data resource, it embeds the contents of schema.graphql verbatim inside a TypeScript template literal (backtick string). Any backtick (`) or @-prefixed identifier inside a GraphQL docstring (""" … """) breaks the generated TypeScript:

  • a backtick in a docstring prematurely closes the template literal → cascade of TS syntax errors;
  • an @name inside a docstring can be parsed as a misplaced decorator.

The generated data resource then fails to compile. The raw read is in gen1-app.js (file(relativePath)); the unescaped value flows into the data-resource renderer that wraps it in the template literal.

Expected behavior

The schema string should be escaped for template-literal embedding (at minimum escape ` and ${) before being written into the generated TypeScript, so arbitrary docstring text round-trips and the generated data resource compiles.

Reproduction steps

  1. In a Gen 1 project, add a docstring with a backtick and/or an @-identifier to schema.graphql:
"""
Prefer the new field. The `legacy` path is @deprecated.
"""
type Note @model { id: ID! body: String }
  1. Run npx amplify gen2-migration generate.
  2. Open the generated data resource (e.g. amplify/data/resource.ts): the schema template literal is broken (unterminated string from the stray backtick; @deprecated left sitting as a decorator).
  3. TypeScript fails to compile the generated file.

Project Identifier

No response

Log output

Details
# Put your logs below this line


Additional information

The correct fix is to escape the schema string before embedding (escape ` and ${). As a non-invasive workaround we sanitize docstrings on read in gen1-app.js — strip leading @ from identifier-like patterns and replace backticks with single quotes inside """ """ blocks (docstrings are descriptions, not directives, so this is cosmetic):

     file(relativePath) {
-        return (0, node_fs_1.readFileSync)(node_path_1.default.join(this.ccbDir, relativePath), 'utf8');
+        let content = (0, node_fs_1.readFileSync)(node_path_1.default.join(this.ccbDir, relativePath), 'utf8');
+        if (relativePath.endsWith('schema.graphql')) {
+            content = content.replace(/"""[\s\S]*?"""/g, (m) =>
+                m.replace(/@(?=[a-zA-Z])/g, '').replace(/`/g, "'")
+            );
+        }
+        return content;
     }

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions