gnarroway / tako

A Clojure library for efficient data access using batching and caching.
9 stars 0 forks source link

Usage with lacinia-pedestal #1

Open bday2009 opened 3 years ago

bday2009 commented 3 years ago

Hello, thank you for this library. I'm using superlifter to handle batching for my lacinia GraphQL server and I'd like to compare the two libraries. lacinia provides lacinia-pedestal to quickly hook up a pedestal service for GraphQL. I'm looking at the documentation of tako and I'm not sure how to clean up the loaders using lacinia-pedestal, as it does not use lacinia/execute function. From looking at lacinia-pedestal source code I thought this would be the place to do that: https://github.com/walmartlabs/lacinia-pedestal/blob/master/src/com/walmartlabs/lacinia/pedestal/internal.clj#L198 So maybe:

(defn ^:private execute-query
  [context]
  (let [request (:request context)
        {q :parsed-lacinia-query app-context :lacinia-app-context} request
        result (executor/execute-query
                 (assoc app-context constants/parsed-query-key q))]
    ;; clean up here
    result))

Then replace the interceptor with enter fn here: https://github.com/walmartlabs/lacinia-pedestal/blob/master/src/com/walmartlabs/lacinia/pedestal/internal.clj#L206

What do you think? Maybe tako can provide an utility function to set this up quickly?

gnarroway commented 3 years ago

Hi there, thanks for discovering my library and trying to try it out :)

I’ve only used it with lacinia/ring/jetty so far but seeing how it could work with pedestal would be interesting. Thank you for your suggestions.

I am going to flesh out the docs a bit more and also knock up some concrete example apps as it’s probably easier to understand how to hook it up. I will check out lacinia-pedestal during this exercise.

bday2009 commented 3 years ago

That would be very cool. Thank you!

gnarroway commented 3 years ago

Hi @bday2009,

I added a section on how to use this with pedestal. Let me know if it works for you.