我正在将express与Neo4j graphql一起使用。
在我的代码中看到此异常而没有特定的行指示。
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "[object Array]".] { code: 'ERR_UNHANDLED_REJECTION' }
Node.js v20.3.0
我在“graph-data-models.js”中定义了图形数据模型
...
const driver = neo4j.driver(
...
);
const ObjectGraphMap = new OGM({ typeDefs, driver });
const Challenge = ObjectGraphMap.model("Challenge");
...
Express 服务器位于 “app.js”。服务器应该从这里开始。我跑
node app.js
。
...
try {
await ObjectGraphMap.init();
app.listen(port, () => {
logger.info(`Data API App listening at http://localhost:${port}`);
});
} catch(e) {
logger.error("OGM init failed",e);
}
API 定义在 "api.js"
...
app = express()
...
app.get("/challenges", getChallenges);
...
...
const getChallenges = async (req, res) => {
try {
...
Challenge.find({
... }
})
.then((challenge) => {
...
})
.catch((err) => {
...
});
} catch (error) {
...
}
}
...
在我看来,它不仅仅是在所有地方都包裹着 try-catch。如何调试并找出问题所在? OGM init 需要一些更改,但需要在 “app.js” 上捕获模型。
...
ObjectGraphMap.init()
.then(() => {
...
})
.catch(() => {
...
})
...
不切它。
然而,这并不是真正的解决方案。 我在模式上添加了一个字段(用于实例化驱动程序 - 变量 typeDefs)。所以,
ObjectGraphMap.init()
失败了。 唉,Neo4j(还)没有与 graphql 进行灵活的模式集成。它可能并没有那么糟糕,因为它可以变得非常动态并且容易出错,而无需硬修复模式。PS:Stacktrace 还需要改进。实际上并没有将其标记为答案,因为 ES 上似乎有一些问题需要解决。检查这个
出。