-
Notifications
You must be signed in to change notification settings - Fork 765
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
using async resolvers for third-party api calls #870
Comments
I'm running into the same issue, haven't found a definite solution yet but DjangoChannelsGraphqlWsl seems to be promising. What caught my eye was:
|
I guess you should pass a non-default executor to the view: from graphql.execution.executors.asyncio import AsyncioExecutor
graphql_view = GraphQLView.as_view(executor=AsyncioExecutor()) |
Apparently setting executor doesn't work. It would be nice to have this since Django 3.1 already have async views. |
It would be really nice to have a separate |
@jkimbo created a repl to showcase dataloaders with graphene 3 / async resolvers. |
If someone want to give a hand, I started a PR to add an async view to |
NOTE: self is busted. maybe it's would something like this work or does the view itself have to be async? maybe it would work with gevent but not Asyncio executors?
|
strawberry django plug-in comes with async. Worked without any problems for me: https://strawberry.rocks/docs/integrations/django#async-django |
Hi, I'm trying to do some api calls outside of django with graphene-django. However, I cannot figure out how to do this with the
GraphQLView
fromgraphene_django.views
inurls.py
.schema.py
This schema works when I run it in a simple test by executing
python async_resolvers_test.py
. It will print{'randomNumbers': [{'number': 70}, {'number': 2}, {'number': 34}, {'number': 34}, {'number': 70}]}
within a second as the individual requests are called parallel.async_resolvers_test.py:
Now, I would like to do the same thing for every execution with
graphene-django
, but I cannot work out how to do this. I have tried many things, but nothing works (for example addingexecutor=AsyncExecutor()
toGraphQLView.as_view(...)
).urls.py:
I am getting this error:
There is no current event loop in thread 'Thread-1'
, when I try to execute in GraphiQL:I am sure this has something to do with not properly setting up an async session, but I get very confused with everything that is out there and I thus have no idea how to do this.
Please let me know if you have any idea or if anything here is unclear. Thanks in advance!
The text was updated successfully, but these errors were encountered: