graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

Add async view

Open fabienheureux opened this issue 3 years ago • 3 comments

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

fabienheureux avatar Aug 26 '21 07:08 fabienheureux

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

Suor avatar Aug 26 '21 08:08 Suor

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

fabienheureux avatar Aug 26 '21 11:08 fabienheureux

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.

Suor avatar Aug 26 '21 13:08 Suor

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

erikwrede avatar Sep 29 '22 05:09 erikwrede

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

ayyoubelamrani4 avatar Oct 20 '22 19:10 ayyoubelamrani4

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 😓

fabienheureux avatar Oct 20 '22 23:10 fabienheureux

Closed in favor of https://github.com/graphql-python/graphene-django/pull/1394

firaskafri avatar Apr 11 '23 11:04 firaskafri