Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module "./resolvers/crud" has already exported a member #465

Open
baumandm opened this issue Sep 3, 2024 · 0 comments
Open

Module "./resolvers/crud" has already exported a member #465

baumandm opened this issue Sep 3, 2024 · 0 comments
Labels
bug Something isn't working community Something initiated by the community

Comments

@baumandm
Copy link

baumandm commented Sep 3, 2024

Describe the Bug

After upgrading to 0.28.0 to address #450, I'm getting generated files that fail the TypeScript build with errors like this:

prisma/generated/typegraphql/index.ts:16:1 - error TS2308: Module "./resolvers/crud" has already exported a member named 'CreateManyAndReturnItemTypeArgs'. Consider explicitly re-exporting to resolve the ambiguity.

16 export * from "./resolvers/outputs";

This happens because two different classes are generated with the same name, CreateManyAndReturnItemTypeArgs, one in the resolvers/crud folder and one in the resolvers/outputs folder.

Everything worked correctly with the same schema in previous versions of typegraphql-prisma, this is just related to the new CreateManyAndReturn classes.

To Reproduce
Here is a codesandbox that reproduces it, run npm start

Here's a simple schema.prisma repro:

generator client {
  provider = "prisma-client-js"
}

generator typegraphql {
  provider = "typegraphql-prisma"
  output   = "../prisma/generated/typegraphql"

  useSimpleInputs = true
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

model Item {
  id         Int @id @default(autoincrement())
  name       String

  typeId     Int?
  type       ItemType? @relation(fields: [typeId], references: [id])
}

model ItemType {
  id            Int    @id @default(autoincrement())
  name          String @unique
  
  items Item[]
}

I've found three different ways to change the schema so it will build successfully.

  1. Changing the ItemType relation to be required instead of optional. Not sure why this works.
  typeId     Int
  type       ItemType @relation(fields: [itemTypeId], references: [id])
  1. Renaming the relation field to match the model name, type -> itemType
  itemTypeId     Int?
  itemType       ItemType? @relation(fields: [itemTypeId], references: [id])
  1. Leaving the ItemType relation optional, but renaming the ItemType model to something else e.g. Type.
  typeId     Int?
  type       Type @relation(fields: [typeId], references: [id])
}

model Type {
  id            Int    @id @default(autoincrement())
  name          String @unique
  
  items Item[]
}

For (3), it will generate a CreateManyAndReturnItemTypeArgs class and a CreateManyAndReturnTypeArgs class, but they no longer conflict with each other.

After all this investigation, I think the key is (2) and (3). I suspect the issue is that the class name generation works by concatenating a model and the relation field name, but that can cause a conflict with another relation name. Not sure how to get around that without adding some kind of separator between the model name and relation in the generated class name.

If there isn't a clean fix for this, feel free to close it. I will likely go with (2) as a workaround.

Thanks!

Expected Behavior
The generated files should build successfully.

Environment (please complete the following information):

  • OS: Codesandbox
  • Node: v20.12.1
  • typegraphql-prisma version: 0.28.0
  • Prisma version: 5.19.0
  • TypeScript version: 5.5.4
@MichalLytek MichalLytek added bug Something isn't working community Something initiated by the community labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community Something initiated by the community
Projects
None yet
Development

No branches or pull requests

2 participants