graphql-python / graphql-python/graphene-django
DjangoFilterConnectionField with DataLoader
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
Consider a query like this:
```graphql
{
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.
Contributor guide
Assessment
This issue has not been assessed yet.