From 650308ac26cc095b9ac46e4c7fd644f43e154c9c Mon Sep 17 00:00:00 2001 From: Christopher Sundersingh Date: Thu, 18 Apr 2024 15:39:00 -0700 Subject: [PATCH] fix(api): add auto generated comment to the generated typescript data schema file --- .../__snapshots__/generate-ts-data-schema.test.ts.snap | 7 +++++++ .../src/ts-schema-generator/helpers.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/amplify-graphql-schema-generator/src/__tests__/__snapshots__/generate-ts-data-schema.test.ts.snap b/packages/amplify-graphql-schema-generator/src/__tests__/__snapshots__/generate-ts-data-schema.test.ts.snap index 02ba20227d..8211b4bef2 100644 --- a/packages/amplify-graphql-schema-generator/src/__tests__/__snapshots__/generate-ts-data-schema.test.ts.snap +++ b/packages/amplify-graphql-schema-generator/src/__tests__/__snapshots__/generate-ts-data-schema.test.ts.snap @@ -2,6 +2,7 @@ exports[`Type name conversions basic models should generate correct typescript data schema 1`] = ` "/* eslint-disable */ +/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ import { a } from \\"@aws-amplify/data-schema\\"; export const schema = a.schema({ @@ -23,6 +24,7 @@ export const schema = a.schema({ exports[`Type name conversions check all valid datatypes 1`] = ` "/* eslint-disable */ +/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ import { a } from \\"@aws-amplify/data-schema\\"; export const schema = a.schema({ @@ -52,6 +54,7 @@ export const schema = a.schema({ exports[`Type name conversions generates enum imports correctly 1`] = ` "/* eslint-disable */ +/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ import { a } from \\"@aws-amplify/data-schema\\"; export const schema = a.schema({ @@ -71,6 +74,7 @@ export const schema = a.schema({ exports[`Type name conversions postgres schema with database config secret and vpc should generate typescript data schema with configure 1`] = ` "/* eslint-disable */ +/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ import { a } from \\"@aws-amplify/data-schema\\"; import { configure } from \\"@aws-amplify/data-schema/internals\\"; import { secret } from \\"@aws-amplify/backend\\"; @@ -106,6 +110,7 @@ export const schema = configure({ exports[`Type name conversions schema with database config secret and vpc should generate typescript data schema with configure 1`] = ` "/* eslint-disable */ +/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ import { a } from \\"@aws-amplify/data-schema\\"; import { configure } from \\"@aws-amplify/data-schema/internals\\"; import { secret } from \\"@aws-amplify/backend\\"; @@ -157,6 +162,7 @@ export const schema = configure({ exports[`Type name conversions schema with database config without vpc should generate typescript data schema with configure 1`] = ` "/* eslint-disable */ +/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ import { a } from \\"@aws-amplify/data-schema\\"; import { configure } from \\"@aws-amplify/data-schema/internals\\"; import { secret } from \\"@aws-amplify/backend\\"; @@ -186,6 +192,7 @@ export const schema = configure({ exports[`Type name conversions ts schema generator should invoke generate schema 1`] = ` "/* eslint-disable */ +/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ import { a } from \\"@aws-amplify/data-schema\\"; import { configure } from \\"@aws-amplify/data-schema/internals\\"; import { secret } from \\"@aws-amplify/backend\\"; diff --git a/packages/amplify-graphql-schema-generator/src/ts-schema-generator/helpers.ts b/packages/amplify-graphql-schema-generator/src/ts-schema-generator/helpers.ts index e84207fc97..19e75605a1 100644 --- a/packages/amplify-graphql-schema-generator/src/ts-schema-generator/helpers.ts +++ b/packages/amplify-graphql-schema-generator/src/ts-schema-generator/helpers.ts @@ -220,7 +220,14 @@ export const createImportExpression = (containsSecretName: boolean): ts.NodeArra true, ); - const importExpressions = [importStatementWithEslintDisabled]; + const importStatementWithAutoGeneratedComment = ts.addSyntheticLeadingComment( + importStatementWithEslintDisabled, + ts.SyntaxKind.MultiLineCommentTrivia, + ' THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. ', + true, + ); + + const importExpressions = [importStatementWithAutoGeneratedComment]; if (containsSecretName) { importExpressions.push(internalsConfigureImportStatement, secretImportStatement); }