Fork me on GitHub
#pathom
<
2022-09-28
>
nivekuil03:09:49

I'm trying out full-stack dynamic resolvers in fulcro, but it looks like it will slow down first load because the app initialization needs to be async to wait one round trip for the indexes to be fetched first. Any better way to do it? ideally the indexes could be fetched along with the html/css/js and held in a CDN

wilkerlucio14:09:22

what do you mean by "full-stack dynamic resolvers"?

nivekuil22:09:28

use boundary-interface as the remote instead of the normal http remote

wilkerlucio23:09:52

gotcha, so, it really depends on when/how you initialize it, I dont have any mechanism to cache, but there is a way to “trick it”, by wrapping the boundary interface with a fn, and intercepting the request for indexes

wilkerlucio23:09:13

Im afk now, but I can send an example later

nivekuil23:09:52

if you have an example for getting this working at all I'd love to see it. my attempt failed, I believe I couldn't figure out why the boundary-interface seemed to work in the repl but when fulcro calls it a lot of attributes return "Batch error: cannot write Function"

nivekuil23:09:36

also there was ::p/not-found coming from somewhere and I don't even see that in the pathom code

wilkerlucio23:09:43

the error sounds like some encoding issue, which could explain the fail on remote, but not in the repl

wilkerlucio23:09:19

p not found is weird, thats not a thing in pathom 3

nivekuil23:09:22

well, when I say repl I mean cljs browser repl, and it's using the same transit stuff as the normal fulcro http remote

nivekuil23:09:57

proof of not-found

nivekuil23:09:07

that's in fulcro inspect

wilkerlucio23:09:29

are you using pathom3 in both ends?

wilkerlucio23:09:44

because thats a regular pathom na

nivekuil23:09:45

oh wait it's fulcro inspect

nivekuil23:09:56

that must be using pathom2

wilkerlucio23:09:43

makes, could be

nivekuil23:09:29

so if the error-stack only has .js files then the error happened on the client? does it also do full-stack stacktraces?

nivekuil23:09:34

full code

(defn api-request [body]
  (-> (js/fetch (str js/window.location.origin "/api")
                #js {:method  "POST"
                     :headers #js {"Content-Type" "application/transit+json"
                                   "Accept"       "application/transit+json"}

                     :body (fulcro-transit/transit-clj->str body)
                     })
      (p/then (fn [response] (.text response)))
      (p/then' (fn [response] (log/spy (fulcro-transit/transit-str->clj response))))))

(def pathom
  (p/let [api (pcf/foreign-register api-request)]
    (let [env (-> #_(p.plugin/register [init-state-plugin])
                  (pci/register [api])
                  )]
      (p.a.eql/boundary-interface env))))

nivekuil00:09:16

actually strike all that, I realized that I actually had the resolver definition wrong but this was asymptomatic unless using dynamic resolvers

nivekuil00:09:35

still, doesn't work with fulcro since the cljs writer tries to serialize a Function for some reason

wilkerlucio00:09:36

Im very interested in your experience, afaik no one is using it that way, so I expected rough edges, and interested in fixing them :)

wilkerlucio00:09:54

that rel with fulcro is something we can investigate

wilkerlucio00:09:32

does your transit encoder understands pathom resolvers/mutations?

wilkerlucio00:09:55

they are a special type, and pathom providers readers/writters for them

nivekuil00:09:02

yeah, I have pcot/write-handlers merged in

wilkerlucio00:09:08

can you provide an example repo with the things you are trying? I like to see closer

wilkerlucio00:09:15

and try myself

nivekuil00:09:12

it would have to be the whole fulcro project, I can try making a smaller example later

🙏 1
nivekuil00:09:47

I see the problem, it's in the AST that is passed by the boundary interface to the http request. looking at the ast, :component is actually a function, I think it should be a symbol?

{:type :join,
                                     :dispatch-key :user/views,
                                     :key :user/views,
                                     :query [:view/id :view/title],
                                     :component app.ui.view-meta/UserView,
                                     :children [{:type :prop, :dispatch-key :view/id, :key :view/id}
                                                {:type :prop,
                                                 :dispatch-key :view/title,
                                                 :key :view/title}]}

nivekuil00:09:00

I guess that ast needs to be cleaned up before it gets passed to transit

nivekuil01:09:00

so I call (boundary-interface query) and this is correct, then pathom calls the foreign-registered api-request with a bad AST

nivekuil01:09:57

I think I can instead of using EQL, pass a cleaned up AST directly to the boundary interface

wilkerlucio01:09:32

yes you can :)

nivekuil01:09:26

so I'm guessing that the EQL->AST writes the component metadata that fulcro attaches as functions and that's what's breaking transit

wilkerlucio01:09:31

quite possible

nivekuil01:09:33

also the same for the AST that is passed to the remote

nivekuil01:09:44

not sure what the best way to clean it up is though, spectre?

wilkerlucio01:09:10

one good thing is to make transit more resilient, by setting up a default handlwe

wilkerlucio01:09:28

on the writer

nivekuil01:09:33

oh, I remember you mentioning this now.. the default-handler doesn't work in cljs right

nivekuil01:09:14

ah, ok it just works with transito 🙂

nivekuil01:09:32

this look like a bug?

(p/let [res1 (api-request [{:app.api.wikidata/recent-tags [{:>/tag {:tag/qid [:wiki/label]}}]}])
          res2 (api-request [{:app.api.wikidata/recent-tags [{:tag/qid [:wiki/label]}]}])]
    (println res1)
    (println res2))
{:app.api.wikidata/recent-tags [{:>/tag {}} {:>/tag {}} {:>/tag {}} {:>/tag {}} {:>/tag {}} {:>/tag {}}]}

{:app.api.wikidata/recent-tags [{:tag/qid {:wiki/label flag semaphore}} {:tag/qid {:wiki/label microscope}} {:tag/qid {:wiki/label WebTransport}} {:tag/qid {:wiki/label benchmark}} {:tag/qid {:wiki/label Craigslist}} {:tag/qid {:wiki/label Z shell}}]}

nivekuil01:09:51

adding the placeholder should not affect results?

wilkerlucio01:09:52

I see a join missing a vector after :>/tag

nivekuil01:09:16

ah yeah. oops

nivekuil01:09:19

brain fried

😛 1
nivekuil02:09:36

ok this one, 50% sure I didn't mess up

(p/let [p pathom
          res1 (p [{[:wiki/id 9061] [{:wiki/claims [:wiki/predicate {:>/wiki-item [:wiki/id :wiki/label]}]}]}])
          res2 (p [{[:wiki/id 9061] [{:wiki/claims [:wiki/predicate :wiki/id :wiki/label]}]}])]
    (println res1)
    (println res2)
    )
{[:wiki/id 9061] {:wiki/claims [{:wiki/predicate 106} {:wiki/predicate 737} {:wiki/predicate 106} {:wiki/predicate 106} {:wiki/predicate 101} {:wiki/predicate 106} {:wiki/predicate 31} {:wiki/predicate 800} {:wiki/predicate 106} {:wiki/predicate 101} {:wiki/predicate 106} {:wiki/predicate 106} {:wiki/predicate 737} {:wiki/predicate 106} {:wiki/predicate 106} {:wiki/predicate 101} {:wiki/predicate 800} {:wiki/predicate 800} {:wiki/predicate 737} {:wiki/predicate 101} {:wiki/predicate 800} {:wiki/predicate 737} {:wiki/predicate 361}]}}

{[:wiki/id 9061] {:wiki/claims [{:wiki/predicate 106, :wiki/id 188094, :wiki/label economist} {:wiki/predicate 737, :wiki/id 76725, :wiki/label Max Stirner} {:wiki/predicate 106, :wiki/id 201788, :wiki/label historian} {:wiki/predicate 106, :wiki/id 4964182, :wiki/label philosopher} {:wiki/predicate 101, :wiki/id 159810, :wiki/label economy} {:wiki/predicate 106, :wiki/id 2306091, :wiki/label sociologist} {:wiki/predicate 31, :wiki/id 5, :wiki/label human} {:wiki/predicate 800, :wiki/id 58784, :wiki/label Das Kapital} {:wiki/predicate 106, :wiki/id 3242115, :wiki/label revolutionary} {:wiki/predicate 101, :wiki/id 5891, :wiki/label philosophy} {:wiki/predicate 106, :wiki/id 1930187, :wiki/label journalist} {:wiki/predicate 106, :wiki/id 36180, :wiki/label writer} {:wiki/predicate 737, :wiki/id 9235, :wiki/label Georg Wilhelm Friedrich Hegel} {:wiki/predicate 106, :wiki/id 49757, :wiki/label poet} {:wiki/predicate 106, :wiki/id 82955, :wiki/label politician} {:wiki/predicate 101, :wiki/id 8134, :wiki/label economics} {:wiki/predicate 800, :wiki/id 40591, :wiki/label The Communist Manifesto} {:wiki/predicate 800, :wiki/id 295347, :wiki/label Economic and Philosophic Manuscripts of 1844} {:wiki/predicate 737, :wiki/id 76422, :wiki/label Ludwig Feuerbach} {:wiki/predicate 101, :wiki/id 21201, :wiki/label sociology} {:wiki/predicate 800, :wiki/id 470600, :wiki/label The German Ideology} {:wiki/predicate 737, :wiki/id 1170769, :wiki/label The Essence of Christianity} {:wiki/predicate 361, :wiki/id 1518091, :wiki/label Marx siblings}]}}

wilkerlucio02:09:41

check after :>/wiki-predicate, I think its missing the vector there

nivekuil02:09:04

:>/wiki-item is the placeholder

nivekuil02:09:14

it's in the same level as :wiki/predicate

wilkerlucio02:09:50

osrry, I mistyped, haa, but check after :wiki/predicate

nivekuil02:09:26

yeah that should be correct syntax? [:user/id {:user/city [:city/name]}]

wilkerlucio02:09:16

ah, sorry, I misread, reading from the phone,rsrs

nivekuil02:09:19

I wonder if it's not treating it as a placeholder but as a real join

wilkerlucio02:09:36

ir might be a bug

nivekuil02:09:49

the placeholder query works correctly through pathom-viz.. doesn't that use the same foreign env/boundary resolver

wilkerlucio02:09:37

it may be something in the foreign integration

wilkerlucio02:09:00

you are using pathom viz connected to the cljs env or to the server env?

nivekuil02:09:19

I didn't know you can connect it to the cljs env actually

wilkerlucio02:09:01

you can do with the pathom viz connector

nivekuil02:09:30

ah right, that has the ip/host issues we went over earlier.. I should get around to a PR sometime

mitchelkuijpers13:10:49

@U066U8JQJ I also ran into some issues with a placeholder something seems to go wrong with the foreign interface and placeholders. It is fixed if I query the properties one place higher then the placeholder

mitchelkuijpers13:10:13

so

{:foo/id {:>/placeholder [:foo/name]}}
Fails with cannot find path to [:>placeholder :foo/name]
{:foo/id :foo/name {:>/placeholder [:foo/name]}}
Fixes it

wilkerlucio16:10:46

ok, that totally looks like a bug

wilkerlucio16:10:26

can you please start an issue about it?

mitchelkuijpers09:10:25

Yes I managed to reproduce it in a small reproducible case: https://github.com/wilkerlucio/pathom3/issues/159

nivekuil06:09:55

seems like I can get some requests working but merging into fulcro is broken.. anyone try this yet?

Björn Ebbinghaus18:09:52

You can look at the server-side render stuff from Fulcro. There are functions to encode and decode initial-state into the HTML. So you have some state without having to make a request. I use it for translation strings for example.

nivekuil22:09:55

yeah maybe SSR does something special