Skip to content

DjangoFilterConnectionField with DataLoader #437

Open
@patrys

Description

@patrys

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions