Is it a good practice to combine unrelated models in a single GraphQL query in AEM, or should I create separate queries for each model?
Could you please share some insights on this
Solved! Go to Solution.
Views
Replies
Total Likes
When dealing with unrelated models in AEM, it's generally better to use multiple queries. This approach keeps things simple, avoids over-fetching data, and offers better flexibility for performance optimization and caching.
However, if the data from these models is needed together on the same page (and combining them in a single query helps reduce network overhead), then a single query might be justified. But, in most cases where the models are unrelated or used in different contexts, multiple queries are the cleaner and more maintainable choice.
Single Query (Combining Models)
Pros:
Cons
Multiple Queries (Separate Requests for Each Model)
Pros
Cons
Thanks and Regards,
Madhur
Views
Replies
Total Likes
When dealing with unrelated models in AEM, it's generally better to use multiple queries. This approach keeps things simple, avoids over-fetching data, and offers better flexibility for performance optimization and caching.
However, if the data from these models is needed together on the same page (and combining them in a single query helps reduce network overhead), then a single query might be justified. But, in most cases where the models are unrelated or used in different contexts, multiple queries are the cleaner and more maintainable choice.
Single Query (Combining Models)
Pros:
Cons
Multiple Queries (Separate Requests for Each Model)
Pros
Cons
Thanks and Regards,
Madhur
Views
Replies
Total Likes
@ShamliKh Combining queries on different models is great for performance but comes at a cost of readbility.
The usecase and functionality you want to achieve by doing this drives which path you choose.
If models doesn't talk to each other, it is better to have seprated queries for redability, maintance when you scale. You can still achieve performace using peristed queries.
See this documentation from Adobe https://experienceleague.adobe.com/en/docs/experience-manager-learn/getting-started-with-aem-headles...
Views
Likes
Replies