我无法检测到问题。
我正在使用猫鼬,并且解析程序在DB中工作正常,但是在GraphQL中收到此错误:
"errors": [
{
"message": "ID cannot represent value: <Buffer 5d d4 35 8d b1 d1 60 1e 38 34 7b fc>",
"locations": [
{
"line": 8,
"column": 7
}
],
"path": [
"deleteCollection",
"products",
0,
"id"
]....
这是我的突变解析器:
async deleteCollection(parent, args, context, info) {
//find user
const user = await context.User.findOne({ _id: args.id});
//find collection
const collection = await context.Collection.findOne({createdBy: args.id});
//remove collection from user
user.collections.pull(collection._id);
//save user
await user.save();
//find products in collection
const products = await context.Product.find({
collections: { $in: [collection._id] }
});
//for every product in collection, remove it
await products.map(
async (product) => (
product.collections.pull(collection._id), await product.save()
)
);
//delete collection
await context.Collection.deleteOne({
_id: args.id
});
return collection;
},
我确定问题出在这里:
//find products in collection
const products = await context.Product.find({
collections: { $in: [collection._id] }
});
//for every product in collection, remove it
await products.map(
async (product) => (
product.collections.pull(collection._id), await product.save()
)
);
因为如果没有产品集合,当我删除它时,没有错误。
另外,我还在为graphql type Product
使用此解析器:
const Product = {
id: (parent, args, context, info) => {
return parent.id || parent._id;
}
};
请帮助