graphene-django
graphene-django copied to clipboard
graphene-django v3 has broken Data Loaders
Hi there!
Data loaders used to work with graphene-django
, there is a perfectly maintained example of it here https://github.com/ngshiheng/django-graphene-starter .
They don't work anymore after updating graphene
and graphene-django
to v3, even after following the new graphene docs here.
According to these docs though, they seem to work in graphene
v3, so the only thing left to do is make graphene-django
compatible with that behaviour.
It seems that there is work ongoing on trying to make it function again in graphene-django
(https://github.com/graphql-python/graphene-django/pull/1256 and https://replit.com/@jkimbo/Graphene-async#main/schema.pyhttps://replit.com/@jkimbo/Graphene-async#main/schema.py @fabienheureux @jkimbo)
I have two questions:
- Is my diagnostic right or have I missed something? Did
graphene-django
v3 really break this? I would really like to use DataLoader withgraphene-django
v3 as it is a much better solution thangraphene-django-optimizer
, but am stuck right now. - Is the work on solving the issue ongoing, and if yes do you have an approximative ETA? This is quite critical for our business 😬 I would be really happy to help on this issue if needed! 🙂
PS: @syrusakbary, is this on your radar? The support of DataLoader with aiodataloader
seems really nice but it's a big issue for the community if it works in graphene
but not in graphene-django
😅
Thanks!
@felixmeziere you are right that graphene v3 means that the Promise based dataloader no longer works. This is because graphql-core v3 dropped support for custom backends in favour of using asyncio.
I've been trying to find a solution for Strawberry and I think I have one now: https://github.com/strawberry-graphql/strawberry/pull/1313 (which should be possible to port to Graphene by using middlewares)
Basically, using an extension, I wrap all resolvers in the sync_to_async
decorator and that lets me use the Django ORM in an async context. Also by wrapping the dataloader load fn in the sync_to_async
decorator I can get async dataloader to work.
There is still some more testing to do with it but I think it's the right approach.
(I'm no longer contributing to Graphene but thought I'd share in case it helps 🙂 )