I’ve been trying to integrate the new streams into a self-hosted parse server. I cloned the package linked in the video tutorial (Migrating to self-hosted Parse server). Following this post: Using event-syncs in Moralis SDK v2 & Parse Server, I’m successfully able to trigger a webhook via a stream and add new data in my parse server.
The problem arises when I try to update the data (when confirmed changes to ‘true’), I get this error repeatedly:
error: TypeError: Cannot read properties of undefined (reading 'type') {"code":1,"stack":"Error: TypeError: Cannot read properties of undefined (reading 'type')\n at C:\\Users\\Sid\\Documents\\GitHub\\ethernalelves\\ethernal-elves-backend\\node_modules\\parse-server\\src\\Controllers\\DatabaseController.js:1307:27\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}
error: TypeError: Cannot read properties of undefined (reading 'type') {"code":1,"stack":"Error: TypeError: Cannot read properties of undefined (reading 'type')\n at C:\\Users\\Sid\\Documents\\GitHub\\ethernalelves\\ethernal-elves-backend\\node_modules\\parse-server\\src\\Controllers\\DatabaseController.js:1307:27\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}
error: TypeError: Cannot read properties of undefined (reading 'type') {"code":1,"stack":"Error: TypeError: Cannot read properties of undefined (reading 'type')\n at C:\\Users\\Sid\\Documents\\GitHub\\ethernalelves\\ethernal-elves-backend\\node_modules\\parse-server\\src\\Controllers\\DatabaseController.js:1307:27\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}
error: TypeError: Cannot read properties of undefined (reading 'type') {"code":1,"stack":"Error: TypeError: Cannot read properties of undefined (reading 'type')\n at C:\\Users\\Sid\\Documents\\GitHub\\ethernalelves\\ethernal-elves-backend\\node_modules\\parse-server\\src\\Controllers\\DatabaseController.js:1307:27\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}
error: TypeError: Cannot read properties of undefined (reading 'type') {"code":1,"stack":"Error: TypeError: Cannot read properties of undefined (reading 'type')\n at C:\\Users\\Sid\\Documents\\GitHub\\ethernalelves\\ethernal-elves-backend\\node_modules\\parse-server\\src\\Controllers\\DatabaseController.js:1307:27\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}
error while inserting logs {}
On further investigation, (after logging the console output), the process seems to fail when query.find or query.first runs. Interestingly, adding a new row works just fine, the query does not work inside parse-server.
I have tried a number of things, including instaling parse (parse/node) and properly initializing it with the server url, appid and masterkey.
Is anyone expecting something similar? Have tried a lot of things, nothing seems to work - please help!
Code follows:
const Parse = require('parse/node');
import config from '../config';
export async function parseUpdate(tableName: string, object: any) {
// Check if object exists in db
const TableClassName = Parse.Object.extend(tableName);
const query = new Parse.Query(TableClassName);
query.equalTo('transaction_hash', object.transaction_hash);
query.equalTo('log_index', object.log_index);
const result = await query.first();
console.log("result,", result);
if (result) {
// Loop through object's keys
for (const key in object) {
result.set(key, object[key]);
}
return result?.save(null, { useMasterKey: true });
} else {
// Create new object
const newObject = new Parse.Object(tableName);
for (const key in object) {
newObject.set(key, object[key]);
}
return newObject.save(null, { useMasterKey: true });
}
}```