Nexus-plugin-prisma: TS2300: Duplicate identifier

Created on 19 Nov 2019  路  11Comments  路  Source: graphql-nexus/nexus-plugin-prisma

I have this schema.prisma:

model Media {
  id String @default(cuid()) @id @unique
}

model Audio {
  id String @default(cuid()) @id @unique
}

After generating the supporting type of nexus prisma I end up with

interface NexusPrismaTypes {
  Query: {
    media: "Media";
    media: "Media";
    audio: "Audio";
    audio: "Audio";
  }
}

Any idea why those words are not changed to their equivalent plural form (event if they will be grammatically incorrect)?

impaclow scoptypegen typbug

Most helpful comment

+1

All 11 comments

I actually find out that pluralize was causing the issue here. The solution for me was to add following line in the schema generation script:

import * as pluralize from "pluralize";

pluralize.addIrregularRule("media", "medias");
pluralize.addIrregularRule("audio", "audios");

+1

+1

+1

Similar problem with numbers in model names:

    post3: 'Post3'
    post3S: 'Post3'

Currently, last character 's' is generated in the upper case.

Thanks for reporting this. Looks like we need to review our pluralize dep. it really ought to handle pretty much any case I think. Irregular shouldn鈥檛 default to doing nothing. I鈥檓 on mobile now but will check later if we can just better use the pluralize lib e.g. config.

Another example. Model name is staff, so plural is also staff. Then cannot access t.crud.staff for both the list and individual variants of the model

Another thing you can do if your underlying database table name does not have a valid "pluralized" version then you can use the @@map() to point a model at that table and as long as the model name can be pluralized it should work as expected

Also wanted to add this does not work:

pluralize.addIrregularRule("categories", "categoriess");

I am aware prisma recommends to use single instead of plural on the db model, but still, this breaks current deployment. I am on stage where I can rename tables so I am fine, but will not always be the case.

Hello,
since Prisma (Prisma 2) doesn't use anymore pluralize for querying Models, I think the best way to solve this is by using same methods on Prisma:

prisma.user.findOne()
prisma.user.findMany()
prisma.user.createOne()

// etc

// ... so in nexus plugin 

t.crud.user.findOne()
t.crud.user.findMany()
t.crud.user.createOne()

// etc

What do you think?

I agree with @alanstriglio. Removing the need to correctly pluralize every given model name would remove a source of potential gotchas like these.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adarnon picture adarnon  路  3Comments

mihazs picture mihazs  路  4Comments

colinhacks picture colinhacks  路  5Comments

franjohn21 picture franjohn21  路  4Comments

narciero picture narciero  路  3Comments