【发布时间】:2020-02-02 01:48:44
【问题描述】:
我有这个按预期返回的突变:id、url 和描述。
post(parent, args, context, info) {
const userId = getUserId(context);
const user = await context.User.findOne({ _id: userId });
return context.Link.create(
{
url: args.url,
description: args.description,
postedBy: userId
},
}
问题是当我添加这个函数成功更新Refs to children
async post(parent,args,context,info){
const userId = getUserId(context);
const user = await context.User.findOne({ _id: userId });
return context.Link.create(
{
url: args.url,
description: args.description,
postedBy: userId
},
**function(error, createdLink) {
user.links.push(createdLink._id);
user.save(createdLink);
}**
);
}
在 mongoose 和 mongo 中一切正常,但 graphQL 返回 null:
{
"data": {
"post": null
}
}
我做错了什么?
【问题讨论】: