kit-clj / kit

Lightweight, modular framework for scalable web development in Clojure
https://kit-clj.github.io/
MIT License
476 stars 44 forks source link

query-fn middleware not injected in request #119

Closed muthuishere closed 10 months ago

muthuishere commented 10 months ago

If we are using SQL module , The recommended approach to get the query-fn instance is to get it from request (based on guestbook and other examples)


(defn list-products [req]
  (let [{:keys [query-fn]} (utils/route-data req)]    
  (http-response/ok
   (query-fn :list-all-products {}))))

Its not working now , After this PR https://github.com/kit-clj/kit/pull/88/files#diff-3665446eb5dbdc0e0d4f09b49564dcd673de5d4c517acab045ea65c98fa232c2

Either we might need to revert back this code or change the api routes


 (defmethod ig/init-key :reitit.routes/api
   [_ {:keys [base-path]
       :or   {base-path ""}
       :as   opts}]
   [base-path (merge opts route-data ) (api-routes opts)]) 

Personally i feel this way is good , as all the query-fn instances is available , i can use it within. if not I would like to know how to get the :query-fn instance in some other service level

martinklepsch commented 10 months ago

I think the motivation behind this change was that the api-routes function already receives opts as an argument so if you want to expose it you can do that by wrapping your routes like this

(defn api-routes [opts]
  ["" {:query-fn (:query-fn opts)}     ; < this adds the :query-fn key to route-data 
   ["/swagger.json"
    {:get {:no-doc  true
           :swagger {:info {:title "<<ns-name>> API"}}
           :handler (swagger/create-swagger-handler)}}]
   ["/health"
    {:get health/healthcheck!}]])
muthuishere commented 10 months ago

I understand it now, But it could be helpful , if the documents and guestbook app has been updated accordingly. if there are shortage of devs , i can update and raise a PR against the guestbook app

martinklepsch commented 10 months ago

@muthuishere that would be fantastic indeed! 🙌