Is there a trick to be able to hot-reload pathom resolvers and mutations without restarting the http-server/middleware?
ah, yeah, I didn’t show the specs/conform, but basically it’s just argument parsing
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
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.
You can do it without a macro just by doing that by hand, of course
something like this
(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#)))))