This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-18
Channels
- # 100-days-of-code (10)
- # announcements (2)
- # aws (3)
- # beginners (120)
- # boot (6)
- # calva (6)
- # cider (22)
- # cljsrn (3)
- # clojure (145)
- # clojure-greece (1)
- # clojure-italy (7)
- # clojure-nl (24)
- # clojure-russia (90)
- # clojure-spec (21)
- # clojure-uk (80)
- # clojurescript (175)
- # core-async (1)
- # datomic (17)
- # emacs (8)
- # ethereum (5)
- # figwheel (1)
- # figwheel-main (140)
- # fulcro (137)
- # jobs (6)
- # jobs-discuss (3)
- # luminus (3)
- # mount (1)
- # nyc (3)
- # off-topic (39)
- # onyx (1)
- # pedestal (1)
- # re-frame (21)
- # reagent (13)
- # shadow-cljs (60)
- # spacemacs (25)
- # test-check (4)
- # tools-deps (14)
- # uncomplicate (3)
- # vim (18)
how would I run a remote query using fulcro that is not tied to any components? meaning to fetch data used by background actions that'll eventually get turned into UI data but only after some processing?
Think df/load also works with nil as component. Or if you want to specify a query you can just create a component defs with only query that you just use for the load
So (df/load :server-key nil {:post-mutation etc..)
works. If you juat want all the data and no component.
but maybe I'll scrap that entire approach. I guess I still haven't quite figured out how to integrate remote data into my app
given that something is streaming in via websocket and something is loaded on demand
@wilkerlucio I tried using the Query
(OgE) in fulcro-inspect
but I can't type a p
😛
how so, can you please check the logs for the inspector and see if it's showing any errors?
I mean if you right click on the inspector page and ask to Inspect it (to show devtools from the devtools :P), nothing there?
the p
is the only one that fails to type?
odd, can you check which version you are in, I released an update yesterday, I can't reproduce the issue, but I'm interested in figuring it out, not cool to have this broken
works fine when I use https://wilkerlucio.github.io/oge/
1.0.4 is the new one, can you try upgrade the extension and see if the issue persists?
wtf... the rest of inspect works or deps.js broke everything?
you use Windows right? I wonder if has something to do with the OS
just released 1.0.5 using the externs fix, I just noticed when I changed the language in/out the output got much bigger, I set that back and add the externs and seems fine, but I guess you would return to the same issue as before, but without the deps.js
complain
if you on we can make some tests around it, the issue is probably related to parinfer, do you use some extension like Vimium
that hooks on all keyboard?
just ot confirm, same thing on 1.0.5, right?
Also to take into consideration that multiple loads get batched together in the same request
yeah its probably good enough. I guess the issue is the websocket and its streaming nature
its for the shadow-cljs UI which streams everything that is happening on the server to the UI
can't decide if I should just do everything over the websocket instead of trying to combine it with the normal remote
You also have the option of adding a custom remote (like the restffull api example in the book) for more funky stuff over the network.
@thheller about the load, the reason you need a component is to proper merge the data from the server, can be a bit annoying at first but makes merge easy when you have one, and you can create a simple component with just query and ident to merge the load you need
yeah I think I was just fighting the issue due to not having the component class available
that solved that and the data from the websocket is just merged into the proper location
there is a "hack" you can do to reuse so component that have a correct ident and update the query entirely, could do something like: (df/load this [:some/ident "value"] ComponentWithProperIdent {:update-query (fn [q] [:replaced :query :here])})
still, pretty dirty, better have a new one 😛
When I use load-field
with params, I don't receive those params as params argument in defquery-entity
. Rather, they seem to be included in the query. Is that by design? What am I missing here?
With this definition in the server:
(defquery-entity :person/by-id
(value [{:keys [query]} id params]
(timbre/info :query query)
(timbre/info :id id)
(timbre/info :params params)
{:db/id 1
:person/name "Jane"
:person/numbers (vec (repeatedly 10 #(rand-int 100)))}))
Without params, #(df/load-field this :person/numbers)
:query [:person/numbers]
:id 1
:params nil
With params, #(df/load-field this :person/numbers {:params {:amount 4}})
:query [(:person/numbers {:amount 4})]
:id 1
:params nil
@maxt not sure if was a design decision or accident, but yeah, that's how it works, what you can use to go around is use load
with update-query
, something like this:
(df/load this (prim/get-ident this) (prim/react-type this) {:update-query (fn [q] '[(:person/numbers {:amount 4})])})
@wilkerlucio Thank you for replying. Then I know I should try to work around it. Do you happen to know why load-field
works that way? I.e. when is that behaviour useful?
not sure, it may vary according to each case, I can think you wanting to set the param on the join, you could on the parser send it down, but really that is no right or wrong, just some cases will be more convenient on the join, others on the attr
In this example, what I'm trying to achieve is to load a variable number of random numbers. With your suggestion, I was able to get the following to do that
#(df/load this (prim/get-ident this) (prim/react-type this)
{:update-query (fn [q] '[:person/numbers])
:params {:amount 4}})
I was kind of expecting load-field to do just that, but ok. I don't understand the difference between params on the join vs attr thoughthis will just affect where they will be on the server, I guess there is no formal thing and its a feature not many people use, it probably can be better at pointing the right place, I had this though process sometimes already wanting the param to be in a place but it going somewhere else
Another thing: I'd like to transfer #inst between the client and the server. I guess that's something I need to tell transit how to do. Can I do that through fulcro somehow?
@maxt insts are native to transit, so you don't need anything extra for it
and that is what load-field
generates...but you could issue a load-field for :x
, and then one for :y
, or you could issue a load for a manual ident join via load
as (load [:table id] Component {:params ...})
. The latter will put the params on the join, whereas the former will put them on the field. If you were manually parsing (or using pathom) then that is what actually makes the most sense.
for example, if you were loading comments and wanted to send a pagination parameter, you'd want the parameter to appear on comments (say, from inside a Blog entry): (load-field this :comments {:params {:page 1}})
I guess it might make sense to have a third "hook" for top-level parsing called defquery-field
that could handle it as you expect...
@tony.kay Thank you for expanding on why I see the behavior I see.
I don't quite get the params on field vs join part. Do the params get embedded in the query somehow?
I'd expect #(df/load-field this :person/numbers {:params {:amount 4}})
to turn into a query like [{[:person/by-id 1] [:person/numbers]}]
. Are the params also put in there somehow?
load
is meant to load a entire entity(ies), so the parameters go on the ident-based join if you use an ident, but they always go on the join
But you don't talk about list in queries in the book, because it's normally not something that's exposed?
@tony.kay Does fulcro minimize the number of queries to an SQL database when parsing queries (like join-monster or walkable)?
@jaihindh.reddy Fulcro doesn’t say anything about how you get your data from SQL
@maxt It is true that the book doesn’t tell you what query the various load
s generate
Thought so 😅
@jaihindh.reddy Fulcro stops at the network layer…it tries to minimize the number of HTTP requests when you schedule multiple loads/mutations all at once
@maxt I'm sorry, it's there for sure, I just didn't think I was parsing queries, but obviously, the info was in that chapter. Then I do understand what happens, thanks!
@maxt welcome. The defquery*
macros are just there as a quick placeholder for not having to write a top-level parser for beginning apps. You almost certainly want to use something like pathom connect on the back-end to actually parse/satisfy the graph queries.
The server-parser
is just a parser pre-hooked to the endpoints that those macros emit.
@tony.kay I'm using datomic as a backend, would I still use pathom for parsing out things like params?
So, even though Datomic shares pull syntax with Fulcro, in practice you’re going to have schema mis-matches all over the place from what you actually want in your UI.
I’ve been helping Wilker with his pathom docs…you might want to look at this branch/guide:
https://github.com/awkay/pathom/blob/doc-improvements/docs/DevelopersGuide.adoc or just the Connect section of the current published version
There’s also a youtube video where I demo it: https://www.youtube.com/watch?v=gbrdnSsUerI&t=1388s&list=PLVi9lDx-4C_Rwb8LUwW4AdjAu-39PHgEE&index=15
The Query tab of Fulcro Inspect can also use the indexes from connect to give you auto-complete…so you can play with your server from the inspect tool with query autocomplete…it’s really cool
I was under the faulty assumtion that pathom was only for SQL or rest, so I haven't looked at it at all.
@maxt are you using the extension or the in-browser? tabs have been there for quite a while 🙂
@wilkerlucio I just recently switched to the extension. Apparently I didn't check it out enough.
I read the patch and I think the updated book does make it clear that pathom would be useful even with datomic. 👍
yeah, after a while you realize that datomic per see will not have all the information you need (you might need pull parts from external services/databases or even simple computed information), and patching on that by hand can be a lot of work, pathom tries to provide some abstractions so you can avoid most of the hard parts
I was reading about (fulcro.client/clear-pending-remote-requests! my-app)
in the book
where exactly am I supposed to call that from? the fallback handler?
I don’t see the app in the mutation env
so I’ve got this situation and I’m not sure what the best strategy is
(prim/ptransact! this `[;; First update the vehicle
(a.mutations/update-vehicle {...})
;; Then post payment, if unsuccessful handle failure
(a.m.mutations/post-payment {...})
(fulcro.client.data-fetch/fallback
{:action a.m.mutations/handle-failed-payment})
;; These should only happen if post-payment didn't fail
(a.m.mutations/handle-successful-payment)
(a.mutations/add-to-queue {...})
(u.p.state-machine/set {...})
(r/route-to {...})])
i’ve got it working as desired, except i want the last block to only execute if there were no errors, i thought the fallback would have flushed the remaining mutations but they seem to still be executing
i suppose i could check app state to see if they payment was successful, in each of the mutations in the last block, but seems like there should be a way to flush mutation queue on error
@currentoor Any API that requires the top-level app is one you’ll have to use by saving the app to a global atom on startup
ah i see
well, I guess I could, but it would be a global that I create, which would not work since you can put multiple apps on a page/VM
and does fulcro.client/clear-pending-remote-requests!
also clear local mutations?