fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Aleksander Rendtslev 2021-01-26T00:25:32.056300Z

I’m trying to get the “Index Explorer” page to work, but nothing shows up when I press Load index. • I’ve mirrored the patho.clj parser from Fulcro Native Template • I’ve mirrored the middleware as well • I do get what looks like a succesfull response This is what I see:

Aleksander Rendtslev 2021-01-26T00:30:58.058100Z

I tried the Pathom Viz explorer and it throws the following error:

java.lang.RuntimeException: java.lang.Exception: Not supported: class com.wsscode.pathom.connect$fn__31906
	at com.cognitect.transit.impl.WriterFactory$1.write(WriterFactory.java:65)
	at cognitect.transit$write.invokeStatic(transit.clj:167)
	at cognitect.transit$write.invoke(transit.clj:164)
	at com.fulcrologic.fulcro.server.api_middleware$write.invokeStatic(api_middleware.clj:151)
	at com.fulcrologic.fulcro.server.api_middleware$write.invoke(api_middleware.clj:148)
	at clojure.lang.AFn.applyToHelper(AFn.java:160)
	at clojure.lang.AFn.applyTo(AFn.java:144)
	at clojure.core$apply.invokeStatic(core.clj:667)
	at clojure.core$update_in$up__6853.invoke(core.clj:6185)
	at clojure.core$update_in.invokeStatic(core.clj:6186)
	at clojure.core$update_in.doInvoke(core.clj:6172)
	at clojure.lang.RestFn.invoke(RestFn.java:494)
	at com.fulcrologic.fulcro.server.api_middleware$wrap_transit_response$fn__38673.invoke(api_middleware.clj:169)
	at ring.middleware.resource$wrap_resource_prefer_resources$fn__39075.invoke(resource.clj:25)
	at ring.middleware.content_type$wrap_content_type$fn__38877.invoke(content_type.clj:34)
	at org.httpkit.server.HttpHandler.run(RingHandler.java:117)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.Exception: Not supported: class com.wsscode.pathom.connect$fn__31906
	at com.cognitect.transit.impl.AbstractEmitter.marshal(AbstractEmitter.java:194)
	at com.cognitect.transit.impl.JsonEmitter.emitMap(JsonEmitter.java:171)
	at com.cognitect.transit.impl.AbstractEmitter.emitMap(AbstractEmitter.java:85)
	at com.cognitect.transit.impl.AbstractEmitter.marshal(AbstractEmitter.java:184)
	at com.cognitect.transit.impl.JsonEmitter.emitMap(JsonEmitter.java:171)
	at com.cognitect.transit.impl.AbstractEmitter.emitMap(AbstractEmitter.java:85)
	at com.cognitect.transit.impl.AbstractEmitter.marshal(AbstractEmitter.java:184)
	at com.cognitect.transit.impl.JsonEmitter.emitMap(JsonEmitter.java:171)
	at com.cognitect.transit.impl.AbstractEmitter.emitMap(AbstractEmitter.java:85)
	at com.cognitect.transit.impl.AbstractEmitter.marshal(AbstractEmitter.java:184)
	at com.cognitect.transit.impl.JsonEmitter.emitMap(JsonEmitter.java:171)
	at com.cognitect.transit.impl.AbstractEmitter.emitMap(AbstractEmitter.java:85)
	at com.cognitect.transit.impl.AbstractEmitter.marshal(AbstractEmitter.java:184)
	at com.cognitect.transit.impl.AbstractEmitter.marshalTop(AbstractEmitter.java:211)
	at com.cognitect.transit.impl.JsonEmitter.emit(JsonEmitter.java:41)
	at com.cognitect.transit.impl.WriterFactory$1.write(WriterFactory.java:62)
	... 20 more

Aleksander Rendtslev 2021-01-28T00:09:39.082400Z

I’m still trying to figure out this issue, but thank you for helping out! About the default write handler example: What do I need to do with it? Where do I put it? I don’t have any experience with transit, so I’m still trying to decipher what’s happening. I copied the ::pc/indexes output to see if you can see any clues as to which of the functions is the culprit. In that case I can write logic to dissoc the extra properties per the fulcro example. I’m surprised i’m hitting this though: I hardly have any resolvers at all

Aleksander Rendtslev 2021-01-28T00:10:10.082600Z

Aleksander Rendtslev 2021-01-28T00:22:47.083Z

I copied the code from this example first, and lastly the one you linked above: https://blog.wsscode.com/pathom/v2/pathom/2.2.0/connect/exploration.html But where do I put it? In one of my own namespaces, and then I load it? Or should I add it to the parser?

wilkerlucio 2021-01-28T13:06:26.087300Z

hello, looking at your code I can see :com.wsscode.pathom.connect/resolve #function[com.wsscode.pathom.connect/fn--39871], so its trying to send functions over the wire

wilkerlucio 2021-01-28T13:07:03.087500Z

the write handler needs to go in whatever part of your code you do the Transit encoding

wilkerlucio 2021-01-28T13:07:45.087900Z

had you tried using the Pathom Viz standalone app? (with the pathom-viz-connector, the setup there should work)

Aleksander Rendtslev 2021-01-28T18:00:48.096900Z

Hmm, it’s starting to make sense. I’m using the standard wrap-transit-response middleware from fulcro right now

Aleksander Rendtslev 2021-01-28T18:54:24.097500Z

Using this from the Fulcro RAD example worked:

(pc/defresolver index-explorer [{::pc/keys [indexes]} _]
  {::pc/input  #{:com.wsscode.pathom.viz.index-explorer/id}
   ::pc/output [:com.wsscode.pathom.viz.index-explorer/index]}
  {:com.wsscode.pathom.viz.index-explorer/index
   (p/transduce-maps
     (remove (comp #{::pc/resolve ::pc/mutate} key))
     indexes)})
I’ll try to submit it to the fulcro-template and the fulcro-native-templates so they are up to date

1👍
wilkerlucio 2021-01-26T00:41:17.058500Z

you need to add the plugin manually

wilkerlucio 2021-01-26T00:42:37.059700Z

looks like some encoding issue, do you have any nom standard types in your data?

wilkerlucio 2021-01-26T00:42:51.060300Z

and are you using the native app, or via fulcro inspect?

Aleksander Rendtslev 2021-01-26T00:45:53.060600Z

I’m using the native Fulcro App (and the native Pathom Viz app) When you say, none standard types in my data, do you mean the resolver and mutation definitions?:

(defmutation upsert-entry!
  [{:keys [crux-node]}
   {:entry/keys [id
                 text
                 refs] :as entry}]
  {::pc/input #{:entry/id :entry/text :entry/refs}
   ::pc/output [:entry/id]}
  (upsert-entry crux-node entry))

(defresolver entry-resolver
  [{:keys [crux-node]} id]
  {::pc/input #{:entry/id}
   ::pc/output [:entry/text]}
  (repo/get crux-node id))

Aleksander Rendtslev 2021-01-26T00:46:19.060800Z

These, outside of the index-resolver, are the only ones that are registrered right now

Aleksander Rendtslev 2021-01-26T00:48:17.061Z

ohhh

Aleksander Rendtslev 2021-01-26T00:48:26.061200Z

could it be #uuid?

Tyler Nisonoff 2021-01-26T00:49:54.061400Z

good to know! In com.fulcrologic.rad/pathom#parser-args it looks like the trace-plugin is attempted to be added, but guess we still have to add it at the top level?

Aleksander Rendtslev 2021-01-26T00:58:56.061600Z

hmm… This is all I’m registrering now. And I’m still getting the error:

(pc/defresolver index-explorer [env _]
  {::pc/input  #{:com.wsscode.pathom.viz.index-explorer/id}
   ::pc/output [:com.wsscode.pathom.viz.index-explorer/index]}
  {:com.wsscode.pathom.viz.index-explorer/index
   (get env ::pc/indexes)})


(def all-resolvers [index-explorer])

Aleksander Rendtslev 2021-01-26T00:59:25.061800Z

This is my parser:

(defn build-parser [crux-node]
  (let [real-parser
        (p/parallel-parser
          {::p/mutate  pc/mutate-async
           ::p/fail-fast? true
           ::p/env     {::p/reader [p/map-reader
                                    pc/parallel-reader
                                    pc/open-ident-reader
                                    p/env-placeholder-reader]
                        ::p/process-error process-error
                        ::p/placeholder-prefixes #{">"}}
           ::p/plugins [(pc/connect-plugin {::pc/register all-resolvers})
                        (p/env-wrap-plugin (fn [env]
                                             ;; Here is where you can dynamically add things to the resolver/mutation
                                             ;; environment, like the server config, database connections, etc.
                                             (assoc env
                                                    :crux-node crux-node
                                                    :config *config*)))
                        (preprocess-parser-plugin log-requests)
                        p/error-handler-plugin
                        (p/post-process-parser-plugin p/raise-errors)
                        p/request-cache-plugin
                        (p/post-process-parser-plugin p/elide-not-found)
                        p/trace-plugin]})
        ;; NOTE: Add -Dtrace to the server JVM to enable Fulcro Inspect query performance traces to the network tab.
        ;; Understand that this makes the network responses much larger and should not be used in production.
        trace?      (not (nil? (System/getProperty "trace")))]
    (fn wrapped-parser [env tx]
      (async/<!! (real-parser env (if trace?
                                    (conj tx :com.wsscode.pathom/trace)
                                    tx))))))

wilkerlucio 2021-01-26T01:05:50.064100Z

there is an annoying issue with sending the index in pathom 2, that it tries to send the resolver and mutations functions with the index, and that breaks encoding, it shouldnt because we do have a default handler, but this issue seems to keep getting back

wilkerlucio 2021-01-26T01:06:20.065300Z

one way around it is to manually remove this fns from those index before sending (do it at the resolver that exposes the indexes)

wilkerlucio 2021-01-26T01:06:45.066200Z

not sure if thats the problem you are seeing, but I think is worth trying

Aleksander Rendtslev 2021-01-26T01:10:11.066400Z

Is that’s what’s done here? (from the Fulcro example):

(pc/defresolver index-explorer [env _]
  {::pc/input  #{:com.wsscode.pathom.viz.index-explorer/id}
   ::pc/output [:com.wsscode.pathom.viz.index-explorer/index]}
  {:com.wsscode.pathom.viz.index-explorer/index
   (-> (get env ::pc/indexes)
       (update ::pc/index-resolvers #(into [] (map (fn [[k v]] [k (dissoc v ::pc/resolve)])) %))
       (update ::pc/index-mutations #(into [] (map (fn [[k v]] [k (dissoc v ::pc/mutate)])) %)))})

Aleksander Rendtslev 2021-01-26T01:12:28.066600Z

(still not working if that’s the case)

wilkerlucio 2021-01-26T01:35:34.067500Z

yeah , should be it, from the error stack seems like some fn is trying to get encoded

wilkerlucio 2021-01-26T01:35:56.068100Z

a better fix is try to fix the default encoder

wilkerlucio 2021-01-26T01:36:22.069Z

you can try bumping transit, it had a but around default write handler in some versions

wilkerlucio 2021-01-26T02:23:41.070400Z

here is a full configuration example to get default write handler https://github.com/wilkerlucio/pathom-viz/blob/master/src/core/com/wsscode/pathom/viz/transit.cljc

aratare 2021-01-26T06:04:08.074Z

Hi there, I have a console error ERROR [com.fulcrologic.fulcro.routing.dynamic-routing:133] - route-immediate was invoked with the ident [:component/id :main] which doesn't seem to match the ident of the wrapping component (class Main , ident [ null ...]) which I'm not sure how to fix it. Here's what I have:

(defn ^:export init []
  (log/merge-config! {:output-fn prefix-output-fn
                      :appenders {:console (console-appender)}})
  (log/info "Starting App")
  ;; Avoid startup async timing issues by pre-initializing things before mount
  (app/set-root! app Root {:initialize-state? true})
  (dr/initialize! app)
  (app/mount! app Root "app" {:initialize-state? false})
  (dr/change-route! app (dr/path-to Main)))
;; Root
(defrouter RootRouter [_ {:keys [current-state]}]
  {:router-targets [Login Main]}
  (case current-state
    :pending (dom/div "Loading...")
    :failed (dom/div "Loading seems to have failed. Try another route.")
    (dom/div "Unknown route")))

(def ui-root-router (comp/factory RootRouter))

(defsc Root [this {:root/keys [router]}]
  {:query         [{:root/router (comp/get-query RootRouter)}]
   :initial-state {:root/router {}}}
  (dom/div
    (ui-button {:onClick #(dr/change-route this ["main"])} "Go to main")
    (ui-button {:onClick #(dr/change-route this ["login"])} "Go to login")
    (ui-root-router router)))
;; Main
(defsc Main
  [_ _]
  {:indent        [:component/id :main]
   :route-segment ["main"]
   :query         [:main]
   :initial-state {:main {}}
   :will-enter    (fn [_ _] (route-immediate [:component/id :main]))}
  (dom/h1 "Main!"))

(def ui-main (comp/factory Main))
It works fine(?) but that console error is thrown every time I change-route!. Would appreciate any help. Thanks in advance.

tony.kay 2021-01-26T13:46:32.075100Z

:ident (fn [] [:component/id :main])

tony.kay 2021-01-26T13:47:09.075800Z

if you supply a vector (like you did) it means (fn [] [:component/id (:main props)])

tony.kay 2021-01-26T13:47:29.076300Z

and if you supply just a keyword :ident :k it means (fn [] [:k (:k props)])

tony.kay 2021-01-26T13:47:32.076500Z

see book

tony.kay 2021-01-26T13:47:37.076700Z

and docstring

aratare 2021-01-26T14:20:59.077100Z

Ah I see. Thanks for pointing me in the right direction 🙂

aratare 2021-01-26T14:29:41.077700Z

Also I just realised something profoundly silly: I've been reading and using indent the entire time instead of ident.

aratare 2021-01-26T14:29:51.078100Z

That is some massive 🤦 right there

tony.kay 2021-01-26T14:32:01.078400Z

ah yes, and if you do that you don’t get normalization at all 😜

aratare 2021-01-26T14:33:32.079400Z

haha I've looked at fulcro code for so long and it has never occurred to me once that I've been reading it wrong since the beginning

aratare 2021-01-26T14:34:02.079600Z

😅

aratare 2021-01-26T14:39:04.080100Z

and... changing to the right word fixes all the console errors

aratare 2021-01-26T14:39:11.080300Z

yep 🤦

neupsh 2021-01-26T19:19:35.080800Z

hi @tony.kay it is probably small thing but wanted to let you know: when i searched fulcrologic using duckduckgo, it has indexed and shows http://www.fulcrologic.com/home at the top which return 404 resulting in not opening the page from the search results. Trying it manually did redirect to home page but "opening in new tab" or copy pasting it returns 404 as well.