apollo-server-lambda & neo4j-driver
I'm doing a query where I find out the users that someone is following. The console.log of 'collectedNames' in the backend shows the array of 4 users that they are following and all the correct properties. Somehow with the resolve I end up on the frontend with a repeat list of the same user 4 times. Any thoughts on why that could be and/or how I could improve this type of query
ListUsersFollowing: (root, args, context) => {
return new Promise((resolve, reject) => {
let session = driver.session();
let params = { cognitoId: args.cognitoId };
let query = `
MATCH (currentUser:User { cognitoId: $cognitoId }) - [:FOLLOWING] -> (users:User)
RETURN users
;`;
return (
session
.run(query, params)
.then(function(result) {
if (result.records.length < 1) {
return resolve(null);
}
let collectedNames = []; // How you return/resolve with an array
result.records.map(record => {
console.log(
"properties of the record",
record,
record.get("users").properties
);
let user = record.get("users").properties;
collectedNames.push(user);
});
console.log(
"collected names LIST USERS FOLLOWING",
collectedNames
);
return resolve(collectedNames);
})
.catch(error => {
reject(error);
})
);
});
}