我尝试进行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"
]
}
]
}有点笨拙的自动取款机,请帮助有需要的开发人员:)
发布于 2019-05-24 23:32:35
问题解决了。问题是我必须调用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
);
},快乐的日子
https://stackoverflow.com/questions/56277236
复制相似问题