graphql

Matt Butler 2019-03-25T17:44:14.074900Z

I want to write a test around a resolver that returns a ResolverResultPromise. Is there a convenient way to wait and get the resolved value after it's been delivered? Or do I have to register a callback via on-deliver and if so how do you get a value (or more accurately some kind of error data structure/something you can assert on) out of a lacinia.resolve$with_error$reify if that makes sense.

orestis 2019-03-25T18:53:05.076600Z

Is it actually a clojure promise? Can you deref it?

2019-03-25T19:00:16.077900Z

the most straightforward way is to do something like (let [p (promise)] (on-deliver rr-promise p) @p)

2019-03-25T19:00:57.078500Z

that will let you block your normal code on the async-sih/callback-ish code

2019-03-25T19:02:56.078700Z

ResolverResultPromise is not a clojure.core/promise

2019-03-25T19:03:38.079300Z

it doesn't define a way to block on a result, only a way to register a callback to receive a result

hlship 2019-03-25T19:44:36.080200Z

The use of a Clojure promise is how I generally do it in testing myself. Sometimes, I also have an on-deliver! fn convey the value to a core.async channel.

hlship 2019-03-25T19:45:41.081300Z

BTW, being able to treat a Clojure promise as a callback function is a stable but only psuedo-documented behavior of Clojure's promise. It ends up being quick concise here.

hlship 2019-03-25T19:49:46.083300Z

I would consider making a ResolverResultPromise implement the IBlockingDeref interface (and perhaps IDeref and IPending). I'm hesitant to introduce code that should only be used for testing into production code.

Matt Butler 2019-03-25T20:33:54.087600Z

These were my planned approaches, thanks for confirming :) unless im mistaken the on-deliver callback gets a value if a value was delivered, but if an error was delivered (the 3 arity form of deliver!) I seem to get a with_error type. Is there a way to get some data out of that type?