Fork me on GitHub
#fulcro
<
2022-05-15
>
cl_j01:05:25

Hi everyone, in Fulcro, what's the best way to find which backend resolvers are used when querying fields for an frontend component?

tony.kay01:05:59

More of a back-end/pathom question. In pathom 2 you can add in a plugin like this:

(defn profile-plugin
  "Create a profiling plugin for pathom that records the times for resolver/mutation calls. Entries in the stats
   will start with `q:` for query resolution and `m:` when it is a mutation."
  ([] (profile-plugin :pathom))
  ([group-id]
   {::p/wrap-read
    (fn profile-plugin-wrap-read [reader]
      (fn profile-plugin-wrap-read-internal [env]
        (let [k (p/key-dispatch env)]
          (p {:id (str "q: " k)}
            (reader env)))))

    ::p/wrap-parser
    (fn profile-plugin-wrap-parser [parser]
      (fn profile-plugin-wrap-parser-internal [env tx]
        (profile {:id group-id}
          (parser env tx))))

    ::p/wrap-mutate
    (fn profile-plugin-wrap-mutate [mutate]
      (fn profile-plugin-wrap-mutate-internal
        [env k params]
        (let [out (mutate env k params)]
          (cond-> out
            (:action out)
            (update :action
              (fn [action]
                (fn []
                  (p {:id (str "m: " k)}
                    (action)))))))))}))
with requires:
[com.wsscode.pathom.core :as p]
[taoensso.tufte :as tufte :refer [p profile]]
Then see tufte documentation for getting the collected stats

tony.kay01:05:37

You can also wrap the body of each actual resolver with tufte/p to get real performance of a resolver call..sometimes wrap-resolve can do the res without actually calling your code. So, I’ve also written macros to wrap resolver body automatically. That’s actually a better way to get real numbers. If you just want timings, then Pathom itself also has visualization tools that can be used from front-end.

🙏 1
stagmoose15:05:54

I was trying to run todomvc (https://github.com/fulcrologic/fulcro/tree/develop/src/todomvc/fulcro_todomvc). But when I tried to enter a task, there was a pop window saying that "failed to add item to server" My running procedure is listed below: • git clone the fulcro project • npm install at the root of the fulcro project • npx shadow-cljs server like fulcro book said • go to http://localhost:9630/builds to "watch" todomvc • go to http://localhost:9002/todo.html Are there any mistakes made? It looks like a remote server problem. How could I fix this? Thanks in advance 🙏

Jakub Holý (HolyJak)16:05:33

A stupid question, do you run both shadow-cljs and the backend? I use a clone of the TODO MVC in https://github.com/holyjak/fulcro-intro-wshop, check the instructions there

stagmoose01:05:55

I didn't. 😅 Follow your instruction I am able to run the example successfully. Thanks a lot!

stagmoose01:05:05

I want to have a follow-up question: In this picture, shadow-cljs has a http server on the port 9002. And the server.clj also have a http server on port 8080. What's the difference. • http://localhost:8080/todo.html => this works • http://localhost:9002/todo.html => this only has front-end, Entering tasks will cause the problem I mention before

Jakub Holý (HolyJak)08:05:06

Well, that is simple. 8080 is served by the backend so it can also handle backend requests. 9002 only runs the frontend (shadow does that for you as a developer convenience) so any request to the backend will fail b/c there is no backend on that port. (Notice that backend requests go to <same url>/api )

❤️ 1
stagmoose08:05:42

Okay, got it! Thanks for your help and your minimalist fulcro tutorial and exercise. They help a lot!

🙏 1
Jakub Holý (HolyJak)08:05:02

Thank you, that is great to hear!

❤️ 1