fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Casey 2021-02-25T17:30:59.084600Z

Is there a trick to be able to hot-reload pathom resolvers and mutations without restarting the http-server/middleware?

tony.kay 2021-02-26T16:31:55.097400Z

ah, yeah, I didn’t show the specs/conform, but basically it’s just argument parsing

2021-02-25T17:39:19.086800Z

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

tony.kay 2021-02-25T21:24:57.087400Z

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.

tony.kay 2021-02-25T21:25:08.087600Z

You can do it without a macro just by doing that by hand, of course

tony.kay 2021-02-25T21:29:38.087800Z

something like this

tony.kay 2021-02-25T21:29:40.088Z

(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#)))))