Best practices for composite objects #98
-
Hello all! I've been using neogma for the last couple of months on my project. One of the biggest painpoints I have is relating to composite objects. For instance, let's say I need to return to the client the following structure: {
song: {
title: "Song name",
//song attributes...
albums: [
{
name: "album name"
//album attributes...
artists: [
{
name: "artist name"
//artist attributes...
}
]
}
]
}
} In this case, song, album, and artist are all separate nodes. If I want to return an object like this, I would use the queryBuilder to get the nodes, and then create the DTO manually from the database information. I've been using the querybuilder so far, since I need to use apoc and other neo4j features, but it seems kind of tedious/unmaintainable to query all this information in every service of my NestJS app when I want to return a song with this information. Are there any best practices to prevent this/ account for when the objects may change so that I don't have to go into every single service every time my app changes? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey Ivan! Thanks for your comment. Something that would improve it is eager loading relationships which is still not ready. |
Beta Was this translation helpful? Give feedback.
Hey Ivan! Thanks for your comment.
I'm afraid that there aren't any best practices for this. I personally create functions that run queryBuilder operations inside them, like
const getSongsDto = (...
, which transform the object as needed. I then reuse them in my services.Something that would improve it is eager loading relationships which is still not ready.