Loaders question #796
-
First of all, let me say thank you for this amazing project! Really impressed with how much server configuration gets abstracted away by mercurius, allowing me to just focus on my application features. I do however have a question about loaders. Consider the following setup:
Hopefully I understand the loaders syntax and this is indeed how it would look. My question is, since loaders are meant to reduce the number of round trips from the backend to the database, and both enemies and friends resolve to arrays of Users, aren't we making 2 round trips when we could theoretically make just 1 query to the Users collection/table and get back both enemies and friends in a single query? Do loaders already take care of that behind the scenes? Is there a better approach you would recommend? Or should the schema be changed so that there is only one field (perhaps "relationships") which resolves to [RelatedUser], where RelatedUser extends User and maybe has a "relation" property that can be either "enemy" or "friend"...? I feel like I'm missing something; please enlighten me! 😁 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The two calls are unavoidable as Mercurius can't know how enemies and friends are implemented. If you want to reduce them to one single database round trip, you'll need to implement this logic yourself in resolver. |
Beta Was this translation helpful? Give feedback.
The two calls are unavoidable as Mercurius can't know how enemies and friends are implemented. If you want to reduce them to one single database round trip, you'll need to implement this logic yourself in resolver.