I am using express with Neo4j graphql.
Seeing this exception without specific line indications in my code.
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
I have graph data models defined in "graph-data-models.js"
... const driver = neo4j.driver( ... ); const ObjectGraphMap = new OGM({ typeDefs, driver }); const Challenge = ObjectGraphMap.model("Challenge"); ...Express Server on "app.js". Server should start from here. I run
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 Definitions in "api.js"
...
app = express()
...
app.get("/challenges", getChallenges);
...
- Data Models used in "api-impl.js"
...
const getChallenges = async (req, res) => {
try {
...
Challenge.find({
... }
})
.then((challenge) => {
...
})
.catch((err) => {
...
});
} catch (error) {
...
}
}
...
It looks to me like something more than just wrapping around a try-catch at all places. How can I debug and find out the issue? OGM init needs some change but then-catch model on "app.js" like.
...
ObjectGraphMap.init()
.then(() => {
...
})
.catch(() => {
...
})
...
does not cut it.
I figured out the issue after retracing all the steps I made. Unfortunately, it is not related to any of the details I had posted. Partly the reason it took me so long to debug.
However, it is not really the solution for it. I had added a field on schema (which is used to instantiate the driver - variable
typeDefs). So,ObjectGraphMap.init()fails. Alas, Neo4j does not (yet) have the flexible schema integration with graphql. It may be not that bad as it can get pretty dynamic and error-prone without hard-fixing the schema.PS: Stacktrace needs to improve though. Not actually accepting this as an answer because there seems to be something to address on ES. Check this out and this too.