Cauen / prisma-generator-pothos-codegen

The fastest way to create a fully customizable CRUD Graphql API from Prisma Schema.
https://www.npmjs.com/package/prisma-generator-pothos-codegen
95 stars 16 forks source link

Duplicate object name generated #58

Closed timnghg closed 10 months ago

timnghg commented 11 months ago

First, thank you for the great package.

Avoid schema renaming, do you have any suggestion to resolve issues of duplicate object names?

// schema.prisma
model UnitType {
  id    String @id @default(cuid())
  code  String @unique
  units Unit[]
}

model Unit {
  id       String   @id @default(cuid())
  typeCode String
  type     UnitType @relation(fields: [typeCode], references: [code])
}
// generated/Unit/object.base.ts
export const UnitTypeCodeFieldObject = defineFieldObject('Unit', {
  type: "String",
  description: undefined,
  nullable: false,
  resolve: (parent) => parent.typeCode,
});
// generated/UnitType/object.base.ts
export const UnitTypeCodeFieldObject = defineFieldObject('UnitType', {
  type: "String",
  description: undefined,
  nullable: false,
  resolve: (parent) => parent.code,
});
Cauen commented 10 months ago

Thanks for the issue and sorry for this late You've found a good case

To fix this you can do one or both of the following approaches:

  1. Change the option option.crud.exportEverythingInObjectsDotTs to false. This avoids export everthing from generated objects.ts. (I've updated the example with this option to false, once I think most of people dont need this).
  2. Use the new option option.crud.underscoreBetweenObjectVariableNames to generate names using underscore. In your case the variables generate wold be: UnitType_Code and Unit_TypeCode