Fork me on GitHub
#pathom
<
2022-09-17
>
roklenarcic10:09:13

I have tons of namespaces that have resolvers and each has a (def resolvers [….]) at the end, and there’s a central NS that has a parser that collects all these vars. The problem is that in dev workflow, when I edit and save namespaces that have resolvers, the parser NS that uses them doesn’t get reloaded, so I don’t get the changes until I manually reload the parser namespace. What strategy are you using to tackle this problem?

roklenarcic11:09:40

Ok so this basically boils down to a macro that offloads code from defmutation body into a separate defn so when namespace gets reloaded, the new defn gets called

Mark Wardle12:09:33

An alternative approach that works for me is integrant. In general, my resolvers are usually very thin wrappers around a range of different services, so in the end, I often need to both restart those services AND reload the lists of resolvers. As such, I simply use integrant to stop and start everything, and it takes only a few moments, and I know everything is registered properly. e.g. see my integrant configuration: the potentially dynamic list of resolvers https://github.com/wardle/pc4/blob/738fbb9c9d42ec7c3af78aab45ef5267a84fe63f/pc4-server/resources/config.edn#L112 the pathom environment: https://github.com/wardle/pc4/blob/738fbb9c9d42ec7c3af78aab45ef5267a84fe63f/pc4-server/resources/config.edn#L122 the aero reader for referencing integrant components https://github.com/wardle/pc4/blob/738fbb9c9d42ec7c3af78aab45ef5267a84fe63f/pc4-server/src/com/eldrix/pc4/system.clj#L139 [for components that generate resolvers dynamically] and the aero reader for referencing resolvers listed in clojure namespaces: https://github.com/wardle/pc4/blob/738fbb9c9d42ec7c3af78aab45ef5267a84fe63f/pc4-server/src/com/eldrix/pc4/system.clj#L142 so I can be explicit in the list of resolvers to register.

Mark Wardle12:09:13

I'm sure you could do the same with some other component library. And you can usually map a hotkey to do the 'stop','load namespace','start' to make it very quick and easy.

Ben Grabow16:09:02

I normally use a 0-arity defn instead of a def to hold the collections of resolvers. Then when I create a Pathom index I call each defn and pass the result to pci/register. I'm not sure if this becomes performance intensive to rebuild the index every time a resolver changes, but in my experience with ~10s of resolvers its basically instant.

pithyless17:09:32

I pass in a 0-arity function that returns the actual pathom-env to any pathom interface functions. (ie. (boundary-interface (parser-env-fn)) instead of (boundary-interface parser-env)) If all the resolver collections are written as functions (vs cached defs), then you will always have up-to-date parsers. The only issue is performance, since you do not want the indexes to be parsed and rebuilt with every request. I solve this problem with a configuration flag:

(if (:reload-on-request? cfg)
  (fn [] (new-parser-env-fn))
  (constantly (new-parser-env-fn)))
The trick is constantly will cache the results of calling the function once, while the dev mode will rebuild the index with every request.

👍 1
roklenarcic17:09:17

that’s very nice