OGM 在 Neo4j GraphQL Express 服务器上初始化时出现 UnhandledPromiseRejection

问题描述 投票:0回答:1

我正在将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
  1. 我在“graph-data-models.js”中定义了图形数据模型

     ...        
     const driver = neo4j.driver(
     ...
     );
    
     const ObjectGraphMap = new OGM({ typeDefs, driver });
     const Challenge = ObjectGraphMap.model("Challenge");
     ...
    
  2. 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);
    }
    
  3. API 定义在 "api.js"

...
app = express()
...
app.get("/challenges", getChallenges);
...
  1. “api-impl.js”中使用的数据模型
... const getChallenges = async (req, res) => { try { ... Challenge.find({ ... } }) .then((challenge) => { ... }) .catch((err) => { ... }); } catch (error) { ... } } ...
在我看来,它不仅仅是在所有地方都包裹着 try-catch。如何调试并找出问题所在? OGM init 需要一些更改,但需要在 

“app.js” 上捕获模型。

... ObjectGraphMap.init() .then(() => { ... }) .catch(() => { ... }) ...
不切它。

express neo4j neo4j-ogm
1个回答
0
投票
在回顾我所做的所有步骤后,我发现了这个问题。 不幸的是,它与我发布的任何细节无关。部分原因是我花了这么长时间来调试。

然而,这并不是真正的解决方案。 我在模式上添加了一个字段(用于实例化驱动程序 - 变量 typeDefs)。所以,

ObjectGraphMap.init()

失败了。
唉,Neo4j(还)没有与 graphql 进行灵活的模式集成。它可能并没有那么糟糕,因为它可以变得非常动态并且容易出错,而无需硬修复模式。

PS:Stacktrace 还需要改进。实际上并没有将其标记为答案,因为 ES 上似乎有一些问题需要解决。检查这个

© www.soinside.com 2019 - 2024. All rights reserved.