Fork me on GitHub
#graphql
<
2020-02-28
>
chrisulloa17:02:20

Hard to phrase this question well, but I’m looking more into lacinia-pedestal :async option. Looking at the pedestal docs, they have an example of an interceptor returning a channel like so:

(interceptors/defbefore takes-time
      [context]
      (let [channel (chan)]
        (go
         (let [result (lengthy-computation (:request context))
               new-context (assoc context :response (ring-resp/response result))]
           (>! channel new-context)))
        channel))
I have concerns about putting blocking code like this inside of go

chrisulloa17:02:56

Looking at the lacinia-pedestal async-query-executor-handler

(def async-query-executor-handler
  (interceptor
    {:name ::async-query-executor
     :enter (fn [context]
              (let [ch (chan 1)
                    resolver-result (execute-query context)]
                (resolve/on-deliver! resolver-result
                                     (fn [result]
                                       (->> result
                                            (apply-result-to-context context)
                                            (put! ch))))
                ch))}))
It looks like the query is not being executed in a go block… does this mean that the query execution is not happening inside a core.async thread?

chrisulloa17:02:52

I’m thinking one could also run the execute-query in a thread instead, as long as the result gets written to the channel eventually

hiredman19:02:37

lacinia doesn't use core.async at all, what you are looking at is basically the adapter between lacinia and core.async because pedestal uses core.async

hiredman19:02:39

all code is run in a thread, so I am not sure what your final question is

hiredman19:02:50

lacinia queries always execute asynchronously, that is way execute-query returns a promise that is fulfilled later

chrisulloa20:02:40

> Lacinia queries always execute asynchronously This answers my question

chrisulloa20:02:38

in the pedestal example their code is running inside some async process. I wasn’t sure what execute-query was doing here.

souenzzo20:02:37

There is a library (maybe lacinia) that turns graphql queries in "clojure data"? Turn user { id name } in something like {:type :user :elements [:id :name]}

souenzzo20:02:18

`com.walmartlabs.lacinia.parser.query/parse-query
` Nice!

👀 4