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.

Background

Fulcro Inspect is still written in Fulcro 2, while the modern, Pathom 3 compatible Pathom Viz is written in Fulcro 3 and thus cannot be re-integrated into Fulcro Inspect.

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:

  1. Add pathom-viz-connector to your deps.edn

  2. 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.

  3. (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)
Fulcro Pathom 3 parser with Pathom Viz integration
(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)
1Do not pass in env middleware here
2Instead, apply env-middleware via a plugin - that way both normal processing and Pathom Viz will get the effect
3Use 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.

Tags: Fulcro


Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob