Fork me on GitHub
#fulcro
<
2021-01-26
>
Aleksander Rendtslev00:01:32

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 Rendtslev00:01:58

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

wilkerlucio00:01:37

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

wilkerlucio00:01:51

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

Aleksander Rendtslev00:01:53

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 Rendtslev00:01:19

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

Aleksander Rendtslev00:01:56

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 Rendtslev00:01:25

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

wilkerlucio01:01:50

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

wilkerlucio01:01:20

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

wilkerlucio01:01:45

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

Aleksander Rendtslev01:01:11

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 Rendtslev01:01:28

(still not working if that’s the case)

wilkerlucio01:01:34

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

wilkerlucio01:01:56

a better fix is try to fix the default encoder

wilkerlucio01:01:22

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

Aleksander Rendtslev00:01:39

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 Rendtslev00:01:47

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?

wilkerlucio13:01:26

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

wilkerlucio13:01:03

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

wilkerlucio13:01:45

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

Aleksander Rendtslev18:01:48

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

Aleksander Rendtslev18:01:24

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

👍 3
aratare06:01:08

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.kay13:01:32

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

tony.kay13:01:09

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

tony.kay13:01:29

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

tony.kay13:01:37

and docstring

aratare14:01:59

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

aratare14:01:41

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

aratare14:01:51

That is some massive facepalm right there

tony.kay14:01:01

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

aratare14:01:32

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

aratare14:01:04

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

neupsh19:01:35

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.

tony.kay00:01:01

Fixed. Thanks. I recently deployed a new site that uses diff URIs.