【发布时间】:2021-12-26 23:52:24
【问题描述】:
我正在开发一个在后端使用 GraphQL 的应用程序,我想实现一个人脸比较方法。我正在使用facepp npm package,它为我提供了一个 API 来执行比较。我遇到的问题是,当我的解析器运行时,它会在收到来自 facepp 的响应之前完成。如何让它返回来自 facepp 的响应?
module.exports = {
Mutation: {
checkFace: async () => {
console.log("Checking.....");
let confidence;
var parameters = {
image_url1: "link to image 1",
image_url2: "link to image 2",
};
facepp.post("/compare", parameters, function (err, res) {
if (!err) {
confidence = res.confidence;
//return res.confidence doesn't work
} else {
confidence = "There was an error"
}
});
return confidence
},
},
};
【问题讨论】:
-
不要复制...使用等待!!
-
你能再澄清一下吗?请问有什么办法?
标签: javascript node.js graphql facepp