From aabeb5c7638d1f33a783fc6f366f974af83087c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Mon, 3 Jun 2024 13:55:41 -0600 Subject: [PATCH] import relations as ts types to fix circular imports --- src/components/file.component.ts | 4 ++++ src/convertor.ts | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/file.component.ts b/src/components/file.component.ts index 3094ac2..64171fa 100755 --- a/src/components/file.component.ts +++ b/src/components/file.component.ts @@ -86,6 +86,10 @@ export class FileComponent implements Echoable { `${relationClassName}`, FileComponent.TEMP_PREFIX + relationClassName, ) + this.registerImport( + `type ${relationClassName} as ${relationClassName}AsType`, + FileComponent.TEMP_PREFIX + relationClassName + ) }) this.prismaClass.enumTypes.forEach((enumName) => { this.registerImport(enumName, generator.getClientImportPath()) diff --git a/src/convertor.ts b/src/convertor.ts index c08d547..81a165b 100755 --- a/src/convertor.ts +++ b/src/convertor.ts @@ -387,7 +387,11 @@ export class PrismaConvertor { if (type) { field.type = type } else { - field.type = dmmfField.type + if (dmmfField.relationName) { + field.type = `${dmmfField.type}AsType` + } else { + field.type = dmmfField.type + } } if (dmmfField.isList) {