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

Add async view #1256

Closed

Conversation

fabienheureux
Copy link

@fabienheureux fabienheureux commented Aug 26, 2021

Async view for django >= 3.1

Description

This is still a work in progress, but based on repl from @jkimbo (https://replit.com/@jkimbo/Graphene-async#main/schema.pyhttps://replit.com/@jkimbo/Graphene-async#main/schema.py) I got an async view working for graphene.

I think this should be part of graphene django.

You can use it like this for now

from django.conf.urls import url
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import AsyncGraphQLView

#  ... your django urls
urlpatterns += [ url(r"^graphql$", csrf_exempt(AsyncGraphQLView.as_view(schema=schema, graphiql=True)))]

🖖 any kind of help / review, even at this stage is much appreciated as I am not really experienced with graphene internals, and there might be some area for improvement here.
Thanks !

TODO

  • Add examples with async resolvers
  • Add tests
  • Add documentation

@Suor
Copy link

Suor commented Aug 26, 2021

Is it possible to mix sync and async resolvers this way?

@fabienheureux
Copy link
Author

fabienheureux commented Aug 26, 2021

Is it possible to mix sync and async resolvers this way?

You should be able to using @sync_to_async decorator.
As I said in the description of the PR, I don't have a strong experience with graphene / async django, but I need it in a specific project, so feel free to try it out with the code from this PR or this repo https://github.com/fabienheureux/graphene-async

@Suor
Copy link

Suor commented Aug 26, 2021

I meant if one has 100 sync resolvers already and only wants to add a few async ones, how should one proceed? Even if front-end guarantees to not mix sync and async queries.

@erikwrede
Copy link
Member

@Suor mixing Sync and async resolvers is handled directly by Graphql-Core, not by the view. So that will work.

@ayyoubelamrani4
Copy link

What are the next steps on this one? It would be very helpful to have async views with graphene django 🙏🏼

@fabienheureux
Copy link
Author

Hey, sorry I have not been using this project since a few months, I am not sure when I will be able to catch up, I hope before the end of 2022 but I am buried under a lot of client work at the moment 😓

@jaw9c jaw9c mentioned this pull request Apr 2, 2023
2 tasks
@firaskafri
Copy link
Collaborator

Closed in favor of #1394

@firaskafri firaskafri closed this Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants