I have a working resolver (similar to defquery-root) and working query: [(:find/device {:rgt "123"})
(pc/defresolver device-resolver [env params]
{::pc/output [:find/device]}
(let [rgt (get-in env [:ast :params :rgt])]
{:find/device (find-device-by-rgt rgt)}))
;; query
[(:find/device {:rgt "123"})]
;; result
{:find/device
{:device/rgt "ZZ",
:device/id 123}}
How to fetch the result? df/load! ? something low level? I would like to fetch the data and then use merge/merge-component!@mroerni Thank you very much
I would do it like this:
(pc/defresolver device-rgt->id-resolver [env {rgt :device/rgt}]
{::pc/input #{:device/rgt}
::pc/output [:device/id]}
(find-device-by-rgt rgt)))
(defsc Device [_ _]
{:query [:device/rgt :device/id]
:dent :device/id}) ; or rgt
(df/load! app-or-comp [:device/rgt "ZZ"] Device)
This will handle the load and the merge.
You can decide where to put it in your client db with :target
or use :post-mutation
if you want to do something more complicated.Thanks, But how to call the resolver for autocomplete? https://book.fulcrologic.com/#_the_server_query ?
@holyjak The updated https://fulcro-community.github.io/guides/tutorial-eql-pathom-overview/index.html in the https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/#_prerequisities is much more helpful to beginner of EQL. Thanks!
It's work of @alex-eberts, I just link to it :)
But the link is helpful to me. Thanks @alex-eberts!
You can load on a global attribute (`:find/device`) and load!
takes a params
map.
(df/load! app-or-comp :find/device Device {:params {:rgt "123"}})
@holyjak For a beginner without any experience with React, to be productive with Fulcro, do you think if I should really take the detour to do https://reactjs.org/tutorial/tutorial.html referred in https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/#_prerequisities ? Given my pleasant experience of following the link to EQL Tutorial, I feel that it might be a prudent idea to be eventually more effective.
You don't need to do the tutorial but you need to understand the basics of React. This one seemed as a good entry into that in the limited time I spent looking for something. I'm sure there is an intro more suitable for our unique needs somewhere.. Let me look at this one again..
I think the idea was to just read through the https://reactjs.org/tutorial/tutorial.html#overview part. Does that work for you? Or should we look for something better?
I struggle to find the right intro into react for a Fulcro person. The best one I found so far is perhaps https://dzone.com/articles/fun-with-react-a-quick-overview
@yubrshen I have updated the part about React under https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/index.html#_prerequisities I hope it is more useful now! (should be deployed within 5 min)
@holyjak Thanks! I'm reading your Minimalist Tutorial the second time. I found that I have missed so much in the first reading. Thanks again!
@mroerni Thank you, it works. But now I have the latest resolver. Which is returning list of maps, and there is no unique key. there could be some duplicates. So I am not sure how to load the data into client database.
(pc/defresolver spds-resolver [env params]
{::pc/output [:find/spds]}
(let [device-id (get-in env [:ast :params :device/id])]
{:find/spds (filter-spds (stash-data device-id))}))
{:find/spds [{:spds/ts "20210514154820", :spds/cid "4"}
{:spds/ts "20210514153931", :spds/cid "3"}
{:spds/ts "20210514153931", :spds/cid "3"}
{:spds/ts "20210514153436", :spds/cid "1"}]}
You don't need an ident.
(defsc Spd [_ _]
{:query [:spds/ts :spds/cid]})
(df/load! app-or-comp :find/spds Spd {:params {:device/id 42}})
(:find/spds (app/current-state app-or-comp))
; => The data you are looking for
Or put it wherever with :target
{:params {:device/id 42}
:target [:my-path-somewhere :in-the-db]}
(get-in (app/current-state app-or-comp) [:my-path-somewhere :in-the-db]) ; => The data you are looking for
If you don't know how react should be used, you are bound to run into problems when working with any system that uses react underneath, fulcro included.
But if by experience you meant you haven't used react though you know it in theory, then I'd say that there's not that much to be gained with doing any exercises or such
Then again I used react before I went with reagent and reframe, and now fulcro, so it's just speculation on my part