question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to use AsyncExecutor?

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
Suorcommented, Sep 22, 2020

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

1reaction
jbovenschencommented, Apr 8, 2019

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 https://github.com/graphql-python/graphene/issues/430, and this gist https://gist.github.com/tricoder42/af3d0337c1b33d82c1b32d12bd0265ec

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot Async Executor Management with ... - Medium
Enabling to asynchronous functionality in Spring Boot is very easy with using @EnableAsync annotation over any of Spring Boot configuration ...
Read more >
Spring @Async Executor - java - Stack Overflow
Is there anyway to be able to specify different Executors for different classes? Seems a bit constricting to have to use one Executor...
Read more >
Spring @Async for Asynchronous Processing
An introduction to the spring @async annotation. Learn how enable asynchronous execution support in Spring with @Async and @EnableAsync ...
Read more >
Getting Started | Creating Asynchronous Methods - Spring
Choose either Gradle or Maven and the language you want to use. This guide assumes that you chose Java. Click Dependencies and select...
Read more >
How To Do @Async in Spring - Baeldung
In this tutorial, we'll explore the asynchronous execution support in Spring and the @Async annotation. Simply put, annotating a method of a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found