Fork me on GitHub

This feels like it should be a really silly, obvious FAQ. So I apologize if it is. Is there a recent example of using fulcro with a datomic back-end? All my searches turn up results about a) parsing queries into graphql or b) the deprecated fulcro-datomic library (BTW: thank you so much for picking up where Om Next left off!)


@jimrthy We use Pathom to handle all our backend mutations and queries. This abstracts away whether we're hitting Datomic, HTTP, or some other data store. When handling the request, a middleware adds to the pathom env {:db-ref (atom (d/db datomic-conn))}. Any pathom resolver can access this db to get a consistent read and pull out any data (could be a simple d/pull or something more complicated). We store it as an atom (and not just a value), because if there is a mutation, the mutation will d/transact and reset! the db-ref to the new value. This let's us guarantee read-after-write semantics for a pathom mutation+query. In practice, we separate resolvers that do joins (ala d/q to find entity ids) and resolvers that just fetch attributes (ala d/pull on existing entity ids). All resolvers whitelist attributes returned and check permissions of current-user.


Awesome. Thank you!


@jimrthy I am actually using fulcro with datomic but I haven't find many authorative examples/utility libs either, but I didn't search too much so if there is one I'd like to know too. However the fulcro3-template uses datascript (= datomic-ish) in the back-end: Note that nowadays fulcro (fulcro3 anyway..) leaves the back-end code to pathom.


@jimrthy You can follow Fulcro/other examples that exist for creating your own web server (so not the 'easy' server). Bear in mind that the defquery-root, defquery-entity and defmutation server macros are not coming across to Fulcro 3, and so now the Fulcro server will be a typical Clojure web server with altered middleware. Here run-query is your own function and wrap-api comes from the require: [com.fulcrologic.fulcro.server.api-middleware :as fmw :refer [not-found-handler wrap-api]].


That's awesome! Thank you, especially for the warning about the server-side changes.


You can then println inside run-query, and use the data structure you see there to query Datomic. i.e. run-query will be returning the result map that your Fulcro browser app has requested.

Abhinav Sharma17:08:48

Hello everyone, I was wondering whether anyone could point me to a reasonably sized fulcro project on Github? I have tried using a few keywords but perhaps some open projects have been shared in the channel earlier.


hello, Fulcro Inspect is a good one to look


altough the code is a bit old, has a descent scale

Abhinav Sharma17:08:16

Hmm, got it 👍 I guess, it using fulcro2 right?

✔️ 1
Abhinav Sharma17:08:22

Yup, it is. I was wondering if there are any plans for porting it to Firefox? The FF dev edition is quite decent as well and FF also changed their web extensions mechanism recently.

Abhinav Sharma17:08:56

@U066U8JQJ, thanks for the help!


just no time to support, but would love to have, an old idea is also to have an Electron client, this way you can use on any environment (not just browsers, could be used for React Native for example)

👍 1
Abhinav Sharma17:08:52

Yeah, that sounds cool! I'll be going over the repo soon 🙂


has anyone here ever seen or looked into making a db->tree-like macro that takes a compile-time query and produces an optimized db->tree function?


that wouldn''t work well, queries are dynamic and change all the time, also you have to re-process everything when data changes, so it can't be computed ahead of time. makes sense?


what changes your queries? In apps I work on we use stuff like set-query very rarely


depend on the usage, you can for example use :update-query when you trigger a fetch/load, there you can update as query freely, another helpers like :focus and :without also do query manipulation. but really the point is more about you need the data, reading eql doens't take much time, what could be optimized here is the convertion between EQL -> AST, that can be more easily cached


ahh ok, I suppose fulcro modifies the queries more than expected. I would have asked this in #om but its fairly quiet in there


performance-wise, F3's db->tree is really really fast


it is unlikely to be the source of performance problems in a properly-written app


it is roughly 6x faster to do query processing in F3 than 2. The react overhead is way more than the query processing in most cases.

👍 1

thanks for the insights, checking out this f3 implementation


part of the improvements are in what F3 no longer has to do, but that f2 does


path-meta was half of it, and is no longer needed.


another chunk was adding time to the props as a post-step instead of during parsing (that is part of rendering optimization to know the time of the different bits of props).


then the reimplementation sped up the core db->tree as well. So, overall the total overhead in processing the client UI query is dramatically less


I've been following the fulcro3 tutorial, and section 3.6.2 ( it has an example of pulling the initial state from the repl. Question is which repl? I'm trying in both the shadow-cljs dashboard repl in the browser and the one created in Cursive, but I keep getting

(com.fulcrologic.fulcro.components/get-initial-state app.ui.root/Root {})
Syntax error (ClassNotFoundException) compiling at (REPL:1:1).


is the cursive repl a CLJS repl?


you need a browser connected repl, provided by shadow-cljs


and maybe you need to load namespace you’re in?


i had a the same problem in the fulcro 2 book


I tried using a terminal from within Cursive with npx shadow-cljs cljs-repl main, and it worked fine. F5 in your Chrome browser if your app is not yet running.


The various clj and cljs repls I still find a bit confusing