Skip to content

Is it possible to use AsyncExecutor? #616

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

Closed
artinnok opened this issue Apr 8, 2019 · 5 comments
Closed

Is it possible to use AsyncExecutor? #616

artinnok opened this issue Apr 8, 2019 · 5 comments

Comments

@artinnok
Copy link

artinnok commented Apr 8, 2019

Hello!

How can I use AsyncExecutor with graphene-django?

I try this setup:

# types.py
class Source(graphene.ObjectType):
    value = graphene.String()

# queries.py
class SourcesQuery(graphene.ObjectType):
    sources = graphene.List(
        of_type=Source
    )

    async def resolve_sources(self, info):
        await asyncio.sleep(0.0001)
        return [Source(value='foo'), Source(value='bar')]

# backend.py
class CustomBackend(GraphQLCoreBackend):
    def __init__(self, *args, **kwargs):
        self.execute_params = {
            "executor": AsyncioExecutor(),
            "return_promise": False,
        }

# urls.py
path("graphql", GraphQLView.as_view(
        backend=CustomBackend(),
        schema=graphene.Schema(query=SourcesQuery),
    )),

But this didn't work.
What is wrong?

@jbovenschen
Copy link

If I understand this question correctly, you are trying to implement asynchronous code within the default Django resolver. This is not supported within Django itself as far as I know.

What we did to resolve asynchronous execution of graphql resolvers / subscriptions is to use the django-channels package in combination with apollo-client.

More info can be found here graphql-python/graphene#430, and this gist https://gist.github.com/tricoder42/af3d0337c1b33d82c1b32d12bd0265ec

@artinnok
Copy link
Author

artinnok commented Apr 9, 2019

@jbovenschen thanks!

Do you have working example with AsyncExecutor?

@japrogramer
Copy link

@artinnok like @jbovenschen said in the link to the issue i have this example
graphql-python/graphene#430 (comment)

@dopeboy
Copy link

dopeboy commented May 8, 2019

Closing this down since it looks like it reached resolution. Thanks @jbovenschen for your help here.

@dopeboy dopeboy closed this as completed May 8, 2019
@Suor
Copy link

Suor commented Sep 22, 2020

Why is this closed? There is still no way to use async executor nor resolvers. At least not with provided GraphQLView.

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

No branches or pull requests

5 participants