由于类型不正确,Prisma 更新功能失败
Prisma update function fails because of incorrect type
我正在使用 Prisma2。突变函数如下所示:
const updateUserProfileDetails = async (
inputValues, ctx: { session?: SessionContext } = {}
) => {
const profile = await db.user.update({
where: { id: ctx.session!.userId },
data: {
profile: {
update: {
aboutMe: "this is a random message for about me.", // type error is displayed here
location: "London, UK", // same type error here
profession: "rubber duck", // same type error here
},
},
},
});
return profile;
};
但是,在 aboutMe
、location
、profession
道具上,打字稿尖叫:
Type 'string' is not assignable to type 'NullableStringFieldUpdateOperationsInput | undefined'.ts(2322)
相关架构如下所示:
model User {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
firstName String?
lastName String?
email String @unique
hashedPassword String?
role String @default("user")
sessions Session[]
profile Profile?
}
model Profile {
id Int @default(autoincrement()) @id
aboutMe String?
location String?
profession String?
user User @relation(fields:[userId], references: [id])
userId Int
}
版本:
@prisma/cli: 2.6.0 => 2.6.0
@prisma/client: 2.6.0 => 2.6.0
我一直无法找到(在我通过文件夹搜索时)NullableStringFieldUpdateOperationsInput
的定义。我做错了什么?
您可以将 @prisma/cli
和 @prisma/client
更新为 2.7.1 吗?它在最新版本中运行良好。我试过了,TS 没有在这里抱怨,查询也很好。
我正在使用 Prisma2。突变函数如下所示:
const updateUserProfileDetails = async (
inputValues, ctx: { session?: SessionContext } = {}
) => {
const profile = await db.user.update({
where: { id: ctx.session!.userId },
data: {
profile: {
update: {
aboutMe: "this is a random message for about me.", // type error is displayed here
location: "London, UK", // same type error here
profession: "rubber duck", // same type error here
},
},
},
});
return profile;
};
但是,在 aboutMe
、location
、profession
道具上,打字稿尖叫:
Type 'string' is not assignable to type 'NullableStringFieldUpdateOperationsInput | undefined'.ts(2322)
相关架构如下所示:
model User {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
firstName String?
lastName String?
email String @unique
hashedPassword String?
role String @default("user")
sessions Session[]
profile Profile?
}
model Profile {
id Int @default(autoincrement()) @id
aboutMe String?
location String?
profession String?
user User @relation(fields:[userId], references: [id])
userId Int
}
版本:
@prisma/cli: 2.6.0 => 2.6.0
@prisma/client: 2.6.0 => 2.6.0
我一直无法找到(在我通过文件夹搜索时)NullableStringFieldUpdateOperationsInput
的定义。我做错了什么?
您可以将 @prisma/cli
和 @prisma/client
更新为 2.7.1 吗?它在最新版本中运行良好。我试过了,TS 没有在这里抱怨,查询也很好。