5 ms·
https://gist.github.com/syrusakbary/65fbce1860ef204ee908 https://gist.github.com/syrusakbary/65fbce1860ef204ee908 ;)
by syrusakbary 11y ago
https://gist.github.com/syrusakbary/65fbce1860ef204ee908 https://gist.github.com/syrusakbary/65fbce1860ef204ee908 ;)
- andrewingram 11y agoAh nice, i'll have a look into that a bit more. What's the graphql library that's being imported alongside graphene? Can you see how dataloader might be implemented? The JavaScript version uses magic involving process ticks to aggregate promises within a single run loop, and batch them into a single operation. My knowledge of async in Python isn't deep enough to know whether something similar is possible.
- jhgg 11y agoGraphene is a more pythonic wrapper ontop of a lower-level library called graphql-core[1], which provides async execution using execution middlewares [2]. As far as how a data-loader is implemented, I have a few experiments doing it with gevent, but nothing prod ready. Essentially you can just use the `loop.run_callback` function to get the "next tick" semantics. I combined this along with gevent's AsyncResult to provide a pythonic coroutine based implementation of FB's datawrapper. [1] https://github.com/graphql-python/graphql-core [2] https://github.com/graphql-python/graphql-core/tree/master/graphql/core/execution/middlewares