The DataLoader triggers multiple queries when fetching related entities. #8242
Unanswered
praveengopalan
asked this question in
Q&A
Replies: 1 comment
-
Hi @praveengopalan, Yes — this is the expected behavior when using a group DataLoader. The DataLoader batches the calls efficiently, so even though you see two database queries ( If you want to reduce it to a single query round trip, you can look into using projections or a more optimized data access pattern. With projections, you can shape the result so that However, keep in mind:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Team,
I'm new to GraphQL and currently working on a project that involves related entities such as Order and OrderDetails. I'm using a group DataLoader to fetch OrderDetails, but when I run the following query, it results in two separate database queries:
query Orders {
Orders {
nodes {
id
orderDesc
OrderDetails {
item
amount
quantity
}
Details {
item
amount
quantity
id
}
}
}
}
SELECT id, orderdesc FROM Order
SELECT item, amount, quantity FROM OrderDetails
Is this the expected behavior?
Additionally, is there a more efficient way to execute this query in a single round trip?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions