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.

Document an example of async usage?

See original GitHub issue

I’m not an expert in the python ecosystem, and am not sure what’s required from me to support asynchronous resolvers in an Ariadne schema. If it’s possible, I’d love a brief example illustrating a working async resolver!


What I’ve tried so far (using python 3.7):

from aiodataloader import DataLoader
from ariadne import ResolverMap, gql, start_simple_server

# DATA LOADERS
heroesLoader = HeroesLoader()

class HeroesLoader(DataLoader):
    async def batch_load_fn(self, keys):
        # return await batch_get_heroes()

# SCHEMA DEFINITION
type_defs = gql("""
type Query {
    heroes: [Hero!]!
}

type Hero {
    name: String!
    shortName: String
    title: String
}
""")

# RESOLVERS
query = ResolverMap("Query")
hero = ResolverMap("Hero")

@query.field("heroes")
async def resolve_heroes(*_):
    return await heroesLoader.load('_')

start_simple_server(type_defs, [query, hero])

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rafalpcommented, Feb 2, 2019

If you want to help, please take a look on issues marked with Help wanted.

0reactions
ajhyndmancommented, Feb 2, 2019

I’ll close this issue, since it looks like it’s already on the team’s radar!

Read more comments on GitHub >

github_iconTop Results From Across the Web

async function - JavaScript - MDN Web Docs - Mozilla
The async function declaration declares an async function where the await keyword is permitted within the function body. The async and await ......
Read more >
Task asynchronous programming model - Microsoft Learn
Asynchronous methods that you define by using the async keyword are referred to as async methods. The following example shows an async method....
Read more >
Async/await - The Modern JavaScript Tutorial
The word “async” before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved...
Read more >
JavaScript Async - W3Schools
Example without reject. async function myDisplay() { let myPromise = new Promise(function(resolve) { resolve("I love You !!"); }); document.
Read more >
Asynchronous Programming Using Async/Await in C# - SitePoint
The async keyword is added to the method signature to enable the usage of the await keyword in the method. It also instructs...
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