wagtail-grapple icon indicating copy to clipboard operation
wagtail-grapple copied to clipboard

[WIP] Add Query Optimizer that selects fields from query AST

Open NathHorrigan opened this issue 4 years ago • 6 comments

This is the initial code for optimizing GraphQL queries to reduce the number of database calls. The gist of this PR is that it analyses from the queries' AST what fields of what models it needs and then appends that to the Queryset object, further along the line when a .specific() call is applied these field selects are called on the Queryset using .only(..), .select_related(..) & .prefetch_related(..).

More accurate data will follow...

NathHorrigan avatar Mar 27 '20 18:03 NathHorrigan

What do you think @zerolab??

NathHorrigan avatar Mar 27 '20 18:03 NathHorrigan

Why not consider using https://github.com/tfoxy/graphene-django-optimizer ?

fabienheureux avatar Apr 22 '20 08:04 fabienheureux

Hi @fabienheureux , I did try GDQ but it doesn't work with stream field and that's a big issue for us. Instead of hack GDQ into Grapple, I decided to create our own way of doing it that can be fine tuned and expanded in the future.

NathHorrigan avatar May 05 '20 13:05 NathHorrigan

@NathHorrigan any chance you can bring this to the finish line?

zerolab avatar Oct 29 '20 12:10 zerolab

@NathHorrigan any chance you can bring this to the finish line?

@NathHorrigan any news on this PR? I'm going to fix the merge conflicts 🙂 .

ruisaraiva19 avatar Nov 24 '20 18:11 ruisaraiva19

I started a PR on the graphene_django project to bring async resolvers support out of the box https://github.com/graphql-python/graphene-django/pull/1256 It is still very much a work in progress, but I might be interested in restarting the work on optimizing queries with the addition of dataloaders to avoid n+1 queries once it has been merged 🤞

fabienheureux avatar Aug 26 '21 07:08 fabienheureux