Get insight into Pathom 3 in Fulcro with Pathom Viz
Fulcro has great dev tooling in Fulcro Inspect, however the part for exploring Pathom resolvers and attributes - its Index Explorer - is not compatible with Pathom 3. Here we learn what to do about it.
Updated 2023-03-18 to properly initialize env for queries made from Pathom Viz (by moving env-middleware application into a plugin)
There are two solutions: Either adapt Pathom 3’s indices to the old format, or use Pathom Viz as a standalone application. In both cases you will need pathom-viz-connector.
To adapt Pathom 3 to the existing Fulcro Inspect’s Index Explorer, you can use pathom-viz-connector’s com.wsscode.pathom.viz.ws-connector.pathom3.adapter/env
. However, I have not managed to get this working in the short time I allocated to it.
In my opinion, the better option is to use the newest, shiniest, standalone Pathom Viz. Here is how to connect it to a Fulcro app using Pathom 3:
Add pathom-viz-connector to your
deps.edn
Pass the base-env of the parser through
com.wsscode.pathom.viz.ws-connector.pathom3/connect-env
. This must be the last step, after all resolvers have been registered in the environment, right before it is passed to the parser creation function. Fulcro RAD’s parser offers a function for that.(Re)start your app and open Pathom Viz. It should now see your parser.
Notice that
connect-env
starts a dedicated server on a well-known port, that Viz connects to.
The following requires fulcro-rad version of at least 1.4.5 (January 2023) |
(defn connect-pathom-viz
"Expose indices to standalone Pathom-Viz v2022+"
[env]
(try ((requiring-resolve
'com.wsscode.pathom.viz.ws-connector.pathom3/connect-env)
env {::pvc/parser-id `env})
(catch Exception e
(log/info "NOT enabling Pahom-Viz" e)
env)))
;; A typical example of starting a parser,
;; with only the marked line added to support Viz
(require '[com.wsscode.pathom3.connect.built-in.plugins :as pbip])
(def parser
(let [env-middleware (-> (attr/wrap-env all-attributes)
(form/wrap-env save/middleware delete/middleware)
(asami/wrap-env (fn [_env] asami-connections)))]
(com.fulcrologic.rad.pathom3/new-processor
config
identity ;env-middleware ; (1)
[(pbip/env-wrap-plugin env-middleware)] ; (2)
[automatic-resolvers
form/resolvers
all-resolvers]
connect-pathom-viz))) ; (3)
1 | Do not pass in env middleware here |
2 | Instead, apply env-middleware via a plugin - that way both normal processing and Pathom Viz will get the effect |
3 | Use the new-processor 's 5th argument to pass in the connect-pathom-viz function - this will modify the env as Viz needs after all resolvers etc. have been registered. |