Hello guys!
I have two models: User and Image where a user could have many images.
Now, I have the next situation: User A has images a, b and c saved in the database. If on updateUser mutation I will send just two images, for example, image a and d, I want image b and c to be deleted.
My resolver's current flow is:
1) Check all images associated with the current user
2) Compare images from 1) with images sent as arguments and create one array ( KeepArray ) with images that will be kept (in my case, image a and d because those images are sent as argument) and one more array ( DeleteArray ) which contain what images will be deleted (b and c in my case, because those images aren't sent as arguments)
3) Inside updateUser mutation I'll delete all images from DeleteArray and for images from KeepArray I use upsert
My question is: Can I do those operations in a more efficient way? Here I present a simple example but in my code, I have more complex situations and I want to know if there exists a better way to do that.
Thank you in advance.