DjangoFilterConnectionField with DataLoader
See original GitHub issueConsider 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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
How to combine DjangoObjectType and an additional field in ...
class Query(ObjectType): all_data = DjangoFilterConnectionField( ExampleType, ... How to return two variables from promise DataLoader?
Read more >Dataloader - Graphene-Python
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API...
Read more >graphene Changelog - pyup.io
Graphene now includes an updated version of `aiodataloader` by Syrus Akbary under `graphene.utils.dataloader` due to inactivity of the old repository.
Read more >Solving N+1 in GraphQL Python With Dataloader - Jerry Ng
Tips and guide to handle N+1 problem with Dataloader in Django Graphene while developing GraphQL API in Python.
Read more >graphene: Versions - Openbase
Further contributions and updates to dataloader in this repo are welcome! ... support via DjangoFilterConnectionField and filter_fields attr in Django Meta.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the issue is still relevant. Opening it back.
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.