Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphene-django v3 has broken Data Loaders #1263

Open
felixmeziere opened this issue Oct 1, 2021 · 1 comment
Open

graphene-django v3 has broken Data Loaders #1263

felixmeziere opened this issue Oct 1, 2021 · 1 comment
Labels

Comments

@felixmeziere
Copy link

felixmeziere commented Oct 1, 2021

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 (#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:

  1. Is my diagnostic right or have I missed something? Did graphene-django v3 really break this? I would really like to use DataLoader with graphene-django v3 as it is a much better solution than graphene-django-optimizer, but am stuck right now.
  2. 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 felixmeziere changed the title Graphene Django v3 has broken Data Loaders. Graphene Django v3 has broken Data Loaders Oct 2, 2021
@felixmeziere felixmeziere changed the title Graphene Django v3 has broken Data Loaders graphene-django v3 has broken Data Loaders Oct 2, 2021
@jkimbo
Copy link
Member

jkimbo commented Oct 7, 2021

@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: strawberry-graphql/strawberry#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 🙂 )

charn added a commit to City-of-Helsinki/open-city-profile that referenced this issue Feb 2, 2024
Data loaders that exist are not fully compatible with new versions of
graphene and graphene-django. DjangoConnectionField doesn't seem to handle
loaders correctly and instead return errors like:

"Cannot return null for non-nullable field EmailNodeConnection.edges."

So for now, data loaders will be disabled for this field type.

Use graphql-sync-dataloaders to make other types of fields work with
data loaders.

Some GitHub issues for reference:
- graphql-python/graphene-django#1394
- graphql-python/graphene-django#1263
- graphql-python/graphene-django#1425

Refs: HP-2082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants