reactjs - Ctx.db.mutation."updateAccepted" 不是函数.. Prisma 不会生成突变
问题描述
我尝试制作一个 graphql 突变来更新我现有数据库中的项目。当我尝试执行此突变时,仍然出现错误。
我在项目中添加了“接受”:
我试图部署我的架构但没有任何影响..
type Item {
id: ID! @id
title: String!
image: String
largeImage: String
price: Int!
user: User!
accepted: String!
}
在此之后,我进行了突变:
type Mutation {
updateAccepted(id: ID!): Item!
}
然后我写了解析器:
async updateAccepted(parent, args, ctx, info) {
// 1. Check if the person is logged in
const { userId } = ctx.request;
if (!userId) {
throw new Error('You must be signed in');
}
// 2. find the item
const item = await ctx.db.mutation.updateAccepted(
{
where: { id: args.id },
data: {
accepted: 1
}
},
info
);
// 3. Return the item
return item;
},
当我在操场内执行此功能时,出现此错误
{
"data": null,
"errors": [
{
"message": "ctx.db.mutation.updateAccepted is not a function",
"locations": [
{
"line": 10,
"column": 3
}
],
"path": [
"updateAccepted"
]
}
]
}
有点无能的atm,请帮助有需要的开发人员:)
解决方案
问题解决了。问题是我不得不打电话updateItem
而不是updateAccepted
. 突变在类型上Item
......不是accepted
..
async updateAccepted(parent, args, ctx, info) {
const { id, accepted } = args;
// 1. Check if the person is logged in
const { userId } = ctx.request;
if (!userId) {
throw new Error('You must be signed in');
}
// 2. find the item
return ctx.db.mutation.updateItem(
{
data: { accepted },
where: { id: args.id }
},
info
);
},
快乐的时光
推荐阅读
- python - 合并图像直方图的相似分箱
- javascript - 使用 formData 通过 ajax 发布时,$_POST 保持为空
- javascript - 类型错误:firebase__WEBPACK_IMPORTED_MODULE_2__.firestore 不是函数
- symfony - 添加自定义 Symfony 通知程序通道
- druid - 我可以加入两个数据源并在德鲁伊中永久创建一个新的数据源吗
- gitlab - 使用 Yarn PNP 构建部署时以 PM2 集群模式运行 NestJS
- python - 如何使用@abstractmethod 创建一个抽象接口,指定其构造函数的参数结构?
- excel - 将值粘贴到excel VBA中的过滤表中
- c# - Facebook c# sdk 错误 OAuthException - #2
- android-library - 将独立 Android 库发布到 GitHub 包的标准方法是什么