【发布时间】:2019-10-10 03:31:51
【问题描述】:
我尝试制作一个 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,请帮助有需要的开发人员:)
【问题讨论】:
-
这似乎不是您的 graphql 定义或 prisma 的问题,而是您的数据库驱动程序。你用什么来查询数据库?
-
GraphQL Yoga Server,我基于 Wes Bos 的 Advance React GraphQL 课程构建我的网站
标签: reactjs graphql next.js prisma prisma-graphql