Fork me on GitHub
#fulcro
<
2019-07-12
>
Stefan10:07:13

I’m going through the Fulcro tutorial. I just reached the step where a server handler is added to get some data from the server instead of doing everything locally (http://book.fulcrologic.com/#_implementing_the_server_handler). Has anybody done this tutorial recently? It says I should get an error when doing (df/load app :current-user root/Person) from the client (which I don’t) and after adding ns app.api.read with a defquery-root it should show a network request/response with the user as a response. In the fulcro inspector I do see the request being done in the ‘network’ tab, but the response is empty. I did restart the server (and in fact everything). Any pointers? I can push my code somewhere if needed to understand my situation.

Stefan12:07:14

Looking a bit further, I now suspect that the tutorial is not up to date. The fulcro template is already using a pathom parser instead of the fulcro parser (`wrap-api` in middleware.clj), but the tutorial assumes it’s using the fulcro parser. Is this causing defquery-root to not work? Should I use some pathom-based way of defining the query handler?

hmaurer12:07:20

Hi @stefan.van.den.oord! The tutorial is not up to date I’m afraid. You should be using Pathom to handle queries; Fulcro is moving away from using defquery-root etc and fully embracing Pathom instead.

Stefan12:07:04

Right I suspected as much. Is there a simple change that I can do to get over this hump and proceed with the tutorial? (I mean without having to spend a few hours learning pathom while I’m learning fulcro :)

Stefan12:07:11

(ns app.api.read
  (:require
    [fulcro.server :refer [defquery-root defquery-entity defmutation]]))

(def people-db (atom {1  {:db/id 1 :person/name "Bert" :person/age 55 :person/relation :friend}
                      2  {:db/id 2 :person/name "Sally" :person/age 22 :person/relation :friend}
                      3  {:db/id 3 :person/name "Allie" :person/age 76 :person/relation :enemy}
                      4  {:db/id 4 :person/name "Zoe" :person/age 32 :person/relation :friend}
                      99 {:db/id 99 :person/name "Me" :person/role "admin"}}))

(defquery-root :current-user
  "Queries for the current user and returns it to the client"
  (value [env params]
    (get @people-db 99)))

Stefan12:07:21

That’s the part that is no good anymore then I guess.

hmaurer12:07:32

@stefan.van.den.oord my advice would be to start a project with the lein template and either use that or copy over the server stuff (which uses pathom) to your current project

hmaurer12:07:39

but this might be a bit tricky to do if you’re learning Fulcro

Stefan12:07:18

I did start with a fresh lein template this morning… (`lein new fulcro app`)

hmaurer12:07:34

Ah, so you have Pathom setup there

Stefan12:07:50

It’s in there yes, just don’t know how to get data from the server in this tutorial

hmaurer12:07:57

right; hang on

Stefan12:07:57

(never used any of these things before)

hmaurer12:07:01

are you using VSCode?

hmaurer12:07:24

Would you mind doing a liveshare with me? I don’t have much time now; it will be more efficient to help you this way

Stefan12:07:48

oooh that’s awesome, much appreciated! I’ll set it up…

hmaurer12:07:06

you can PM me the link

Stefan14:07:40

Ok-ish 😉

Stefan14:07:53

I can now load users from the server, but not yet get them to show in the UI.

Stefan14:07:39

I’m finding the down-side of data-driven designs is that it’s hard to tell what’s really happening sometimes.

hmaurer14:07:03

Hmm; do you know why you can’t get them to show in the UI?

Stefan14:07:26

I get an unexpected entry with nils in my person list

Stefan14:07:39

I think i’ll backtrack a few steps and rebuild it more slowly.

hmaurer14:07:55

can you gist me your pathom resolvers? (and your query)

Stefan14:07:30

The nils are not coming from the network, I disabled all the loading on mounting and I still get an entry with nils. I renamed some keywords namespaces in the UI code, I think I messed up somewhere. I’ll just redo that, it’s a good learning experience 😉

Stefan14:07:21

Almost there 🙂 Got all users from the server in the “friends” list; now just add two resolvers for friends and enemies and load those into the corresponding lists.

Stefan14:07:58

Hmm, strange: If I name my resolver friends and have it return a map {:friends ...}, it doesn’t load the data correctly in the UI, but if I name it all-friends and return a map {:all-friends ...} it works. Maybe it doesn’t process the data correctly with my target specification?

(df/load app :all-friends root/Person
         {:target [:person-list/by-id :friends :person-list/people]})

tony.kay15:07:06

@stefan.van.den.oord yeah, I need to take down the tutorial…it is way out of date, and thre is a getting started chapter in the book, so it is largely irrelevant now

Stefan15:07:44

Ah well nothing is as good for understanding something as a broken tutorial 😉

tony.kay15:07:22

yeah, and nothing will drive off new users faster 😜

tony.kay15:07:30

I forgot it was there

Stefan15:07:34

yeah it does require some perseverance 🙂

Stefan15:07:50

So where exactly should I go now for learning Fulcro?

tony.kay15:07:07

see heading in this channel

tony.kay15:07:13

links to book and videos

tony.kay15:07:29

the videos are slightly out of date…but more tolerably than the tutorial

Stefan15:07:50

That web page the one I have been following today…

tony.kay15:07:07

oh, you mean that version of the book is out of date?

tony.kay15:07:18

I thought you meant you were following : http://fulcro.fulcrologic.com/tutorial.html

Stefan15:07:19

Yes, I’m afraid so.

tony.kay15:07:40

ok, so it’s just that the getting started bits assume the template is different than it is?

Stefan15:07:40

No I didn’t see that other one before

Stefan15:07:05

The book doesn’t take phantom into account. In the fulcro template that’s the default now.

Stefan15:07:43

(And I also created a pull request today: https://github.com/fulcrologic/fulcro/pull/318)

Stefan15:07:40

So the book really starts to go wrong from the point where it’s “going remote”.

tony.kay15:07:49

I’ve written waay too much to maintain in docs 😕

tony.kay15:07:30

So, the new book is http://book.fulcrologic.com/fulcro3 but it is out of date later in the book, and requires you use alpha versions of fulcro

Stefan15:07:32

Yeah writing documentation is one thing, but maintaining it…

tony.kay15:07:01

and it does not use the template, but just has you code it from scratch

tony.kay15:07:24

that is a better approach for correctness because it does not use such a moving target (the template)

Stefan15:07:24

From scratch is fine.

Stefan15:07:42

But at this point, what should I learn? Fulcro 2 or 3?

tony.kay15:07:59

you doing commercial products right now?

Stefan15:07:15

no not yet

Stefan15:07:41

What’s a rough ETA for commercial-ready Fulcro 3?

tony.kay15:07:42

just beware that I’m actively working on that book, and minor things may still change in the lib

tony.kay15:07:47

end of summer

Stefan15:07:55

Ok that works for me 🙂

tony.kay15:07:11

it’s already pretty solid…just needs more ppl banging on it

Stefan15:07:17

(redo-from-start)

tony.kay15:07:25

but it is alpha because I may still change the API slightly

tony.kay15:07:49

not a complete redo from start, but a lot of things got significant internal improvements

tony.kay15:07:09

The API is intended to be almost entirely the same, with additions

Stefan15:07:39

Right. So maybe some different conventions then? I’m looking at ALL-CAPS table names?

Stefan15:07:40

(By the way I prefer the “from scratch” approach over the “template” approach, so 👍 )

tony.kay15:07:41

table names are up to you really…convention for most tble names that are remote is to use the id field of the entity (e.g. :person/id)

Stefan15:07:52

Well, enough for today for me, I’ll start over with F3 next time!

jackson20:07:00

I'm having trouble with (abort-request!) in the file-upload example. My app is valid, and the id is correct but the request continues on. Is there any where I can look for more info? I'm not seeing errors in my dev console.