prisma: Prisma WhereUniqueInput typings within node_modules are incorrect/broken

Bug description

Prisma’s typings in node modules for the update function (UserScoresWhereUniqueInput) are wrong. It isn’t including everything from my schema, only the id. I have attempted to reinstall prisma, completely remove the node_modules, and run npx prisma generate again, but none of them succeeded in updating the typings correctly. The schema in the database looks correct, just not in the typings.

How to reproduce

Generate a prisma schema, put something similar to

model UserScores {
	id           Int    @id @default(autoincrement())
    guildId      String
    userId       String
    globalPoints Int
    weeklyPoints Int
}

in it, and try npx prisma generate. The d.ts file in .prisma where it says UserScoresWhereUniqueInput should only include the id.

Expected behavior

I expect UserScoresWhereUniqueInput to contain the rest of the things on the model, like guildId and userId.

Prisma information

Full schema:

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

datasource db {
    provider = "postgresql"
    url      = env("DATABASE_URL")
}

model settings {
    id      Int     @id @default(autoincrement())
    guildId String
    prefix  String
}

model userScores {
    id           Int    @id @default(autoincrement())
    guildId      String
    userId       String
    globalPoints Int
    weeklyPoints Int
}

Database query that is erroring (typescript)

            await prisma.userScores.update({
                where: {
                    userId: message.author.id,
                    guildId: message.guild!.id,
                },
                data: {
                    globalPoints: 0,
                },
            });

Environment & setup

  • OS: Windows 10
  • Database: Postgresql
  • Node.js version: v14.16.0
  • Prisma version:
prisma               : 2.22.0
@prisma/client       : 2.22.0
Current platform     : windows
Query Engine         : query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\prisma-fmt-windows.exe)  
Default Engines Hash : 60cc71d884972ab4e897f0277c4b84383dddaf6c
Studio               : 0.379.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 17 (5 by maintainers)

Most upvoted comments

If you do not have a unique guarantee on the field you want to filter for, you need to use deleteMany or updateMany and it should let you filter as you are trying to.

@janpio

Any suggestions how we could make that clearer or surface it at the right time?

I have colleagues that asked me the same question. I think it is perfectly fine to use updateMany if we dont use uniqueWhere, one DX improve can be adding a suggestion/tip saying:

Do you mean updateMany?

I will try to make a new project and try to reproduce it, if I cant reproduce it myself well then I’ll close the issue.

Also, I can confirm that I have the latest global tsc

I have just realized that this also happens with the delete function, and any function that uses where. ex:

		await prisma.userScores.delete({
			where: {
				guildId: guild.id,
				userId: member.user.id,
			},
		});