Comments (9)
It's better to let users decide what async library they'd like to use. Callbacks are easily integrated with core.async (and Manifold).
from lacinia.
@hlship I think it'd be helpful to have an example of a resolver for async scenario. Did you consider embracing core.async instead of creating customer API for async resolvers? Would it be possible to allow resolvers return a channel that conveys regular resolver result (ResolvedTuple
or anything else)? This would be similar to how pedestal handles async.
from lacinia.
(defn gizmo-resolver
[context args value]
(let [result (resolve-deferred)]
(do-in-a-new-thread
(->> value read-gizmo (resolve-async! result)))
tuple))
from lacinia.
It also seems to me it's something that could be solved using
core.async promise-chan, it's essentially the "deferred" you describe
and since a lot of async stuff (db libraries for instance) in clojure are interfaced with
core.async this would play nicely with them, and allow to plug timeouts and
whatnot at the resolver level super easily with alts!
(defn gizmo-resolver
[context args value]
(let [prom (async/promise-chan)]
(do-in-a-new-thread
(->> value read-gizmo (async/put! prom)))
prom))
About the "executor" context side of things (your ex with do-in-a-new-thread
), I like the idea of letting the end user use whatever he likes and not bake in a complex executor/query planner in lacinia. Then if the user wants to spin the jobs in a vanilla ExecutorService or via go blocks, or some other engine, he's free to do so and has full control over how this happens. In short, imho, lacinia should just define an async container for resolve return value and leave the rest as is, so you just have to take care about the "wait" part on all the promises internally and nothing else.
from lacinia.
Normally I love core.async, but I'm also looking to avoid any further dependencies, and core.async is a big one.
from lacinia.
What about manifold? It's a beautiful API to work with and allows you to define a custom executor.
from lacinia.
I like @mpenet's suggestions. Setting timeouts and handling async execution seems outside the bounds of Lacinia.
Also, Clojure has a built-in "deferred" object api: https://clojuredocs.org/clojure.core/promise. Although I can see why it would be useful to define a new protocol.
from lacinia.
Promise is good to a point, but there isn't an option other than blocking with a timeout and polling with realized?
. The point of the the when-ready!
and resolve-async!
is to provide a third option, where code gets executed when data is available. It's brain dead simple compared to core.async, BUT it's solving a simpler problem: a single "publisher" and single "subscriber".
from lacinia.
Made a few updates; what I long ago called ResolvedTuple
was renamed to ResolverResult
before 0.13.0.
from lacinia.
Related Issues (20)
- "Resolver specified in schema not provided" could be clearer HOT 2
- Published version 1.1 requires missing namespace HOT 1
- In lacinia 1.1, the trace namespace code (dev only) has a dependency on io.aviso/pretty, which is not declared in deps.edn HOT 2
- icu4j vulnerability HOT 1
- Swallowed unhandled exceptions because of misusage of clojure.core/future HOT 10
- Scalar type which returns vector HOT 4
- ::lacinia/null returned in unions instead of null HOT 1
- Apollo Federation Compatibility HOT 1
- Includes variable-definitions in parsed query HOT 4
- Question: Is there a way to return JSON without a corresponding EDN definition? HOT 3
- Use of executor/selection in streamer functions HOT 1
- Document example of a raw JSON scalar
- cryptic errors when input is the wrong type
- Passing in variables wrapped in an array comes in as a double array HOT 5
- Support @defer and @stream directives
- Convert the keys of arguments and variables to kebab-case HOT 1
- Subscriptions may fail to stream data to the client
- Unbalanced braces in queries not causing parse-query to fail
- Tracing "validation" fields are always null
- Question: Query complexity and depth HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lacinia.