graphene-django
graphene-django copied to clipboard
DjangoFilterConnectionField with DataLoader
Consider a query like this:
{
category(id: 1) {
products {
edges {
node {
category {
products {
edges {
node {
category {
products {
edges {
node {
id
}
}
}
}
}
}
}
}
}
}
}
}
}
If someone runs a query like this we are possibly executing hundreds of queries even if the response contains a fairly small number of unique objects. We can use a DataLoader
for the product.category
relation but as category.products
is a DjangoFilterConnectionField
I see no way to have it memorize results within the same execution context.
Ideally I'd want it to only query the database once for each unique combination of category.id
and input parameters (pagination, filterset data). Currently it will fetch the category, then fetch all its products, then for each result once again fetch all products in the category and then once again fetch all products in the category for each of those.
Also curious
I've done this with graphql-js and dataloader, I just treated all the connection arguments as the "id" for the loader. I did bolt on some cleverer logic, but this was the crux of how I solved this.
I've hit this same requirement myself, so i'll see if I can port over my method from Node. The "perfect" solution is variant of Dataloader that's aware of the semantics of connections.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@AndrewIngram just curious if you were able to get this working with grapnehe-django? Working on the same problem at the moment
I think the issue is still relevant. Opening it back.
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Bump