This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-25
Channels
- # announcements (6)
- # asami (1)
- # babashka (80)
- # beginners (89)
- # bitcoin (1)
- # calva (30)
- # cider (33)
- # clj-kondo (1)
- # cljsrn (45)
- # clojars (5)
- # clojure (60)
- # clojure-australia (1)
- # clojure-dev (9)
- # clojure-europe (133)
- # clojure-italy (7)
- # clojure-nl (6)
- # clojure-uk (44)
- # clojurescript (11)
- # conjure (1)
- # data-oriented-programming (2)
- # datahike (13)
- # datascript (4)
- # datomic (19)
- # deps-new (29)
- # depstar (5)
- # duct (39)
- # fulcro (8)
- # girouette (1)
- # helix (10)
- # honeysql (17)
- # jobs (5)
- # jobs-discuss (2)
- # leiningen (6)
- # lsp (51)
- # malli (60)
- # meander (37)
- # membrane (8)
- # off-topic (31)
- # overtone (3)
- # pathom (36)
- # re-frame (8)
- # reagent (30)
- # remote-jobs (2)
- # sci (1)
- # sql (32)
- # startup-in-a-month (3)
- # testing (3)
- # tools-deps (7)
- # xtdb (7)
Is there a trick to be able to hot-reload pathom resolvers and mutations without restarting the http-server/middleware?
Here’s what I do: Make your own macro for defresolver and defmutation that do the following:
• Copy the body into a function with an alternate symbol (e.g. my-resolver-impl
)
• Emit the resolver with the desired symbol, but have it just call the function.
Now when you reload the resolver it redefines the symbol for the generated function, which is what the embedded resolver will call.
(defmacro defresolver [& args]
(let [{:keys [sym arglist doc config body]} (futil/conform! ::mutation-args args)
internal-fn-sym (symbol (str (name sym) "__internal-fn__"))
config (dissoc config :check :ex-return)
env-arg (first arglist)
params-arg (second arglist)]
`(do
;; Use this internal function so we can dynamically update a resolver in
;; dev without having to restart the whole pathom parser.
(defn ~internal-fn-sym [env# params#]
(let [~env-arg env#
~params-arg params#
result# (do ~@body)]
result#))
(pc/defresolver ~sym [env# params#]
~config
(~internal-fn-sym env# params#)))))
Ah interesting idea to wrap it in a macro! Thanks. futil/conform is from om.fulcrologic.fulcro.algorithms.do-not-use
I suppose?
I suppose you could use the same idea to apply authorization requirements to certain mutations and resolvers?
Maybe you can put the creation of your parser behind a function (that is created on every request), then use the var trick, for example: https://github.com/pedestal/pedestal/blob/master/samples/hello-world/src/hello_world/server.clj#L32 Where routes becomes your vector of resolvers/mutations ^ you probably don't want to create the parser on each request in deployed environment though