This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-15
Channels
- # announcements (8)
- # architecture (9)
- # autochrome-github (1)
- # babashka (48)
- # beginners (55)
- # calva (36)
- # cider (16)
- # clj-commons (1)
- # clj-kondo (38)
- # cljs-dev (44)
- # cljsrn (1)
- # clojure (164)
- # clojure-europe (35)
- # clojure-nl (2)
- # clojure-norway (10)
- # clojure-uk (23)
- # clojurescript (50)
- # conjure (24)
- # core-async (1)
- # cryogen (2)
- # cursive (38)
- # datalevin (11)
- # datascript (2)
- # datomic (13)
- # duct (1)
- # emacs (16)
- # events (12)
- # exercism (3)
- # figwheel-main (7)
- # fulcro (26)
- # honeysql (5)
- # integrant (1)
- # jobs (3)
- # kaocha (6)
- # lsp (72)
- # malli (22)
- # nextjournal (35)
- # nrepl (1)
- # off-topic (34)
- # pathom (5)
- # polylith (8)
- # portal (40)
- # re-frame (14)
- # reagent (42)
- # reitit (1)
- # releases (1)
- # remote-jobs (1)
- # reveal (9)
- # sci (2)
- # shadow-cljs (13)
- # sql (3)
- # tools-deps (33)
- # vim (25)
Is it a good idea to use auto-resolved keywords for the qualified-keyword
arg to defattr
? Seems like a reasonable practice to make sure names are easy to track, but on the other hand, the names start getting pretty long with stuff like :com.example.model.foo/bar
.
Why not? You can define alias for the ns => ::foo/bar
What about for cases where the attribute represents a to-many relationship?
(ns com.example.model.account ...)
(defattr ordered-item-names :com.example.model.account.ordered-item/names :ref
Or would you even use the :com.example.model.foo.baz/bar
form in such cases?Maybe I should just be creating an attribute that returns ordered-item ids, and then letting the resolver figure out the associated names of the ordered items, instead of trying to fit the ordered item names into the account model?
> Maybe I should just be creating an attribute that returns ordered-item ids, and then letting the resolver figure out the associated names of the ordered items... This sounds more like it. But if it's performance critical you might want to measure it anyway. A simple resolver that queries the DB directly and returns what you need might also be a good idea. That said, imho there's nothing inherently wrong with your attribute above. I use plenty of "virtual" attributes like this
I think the one "wrong" thing is that it doesn't map directly to the filesystem. So far, I've been using auto-resolved kws and the mappings always line up... but if I tack something at the end of model.foo
like model.foo.baz
, it violates that convention. Of course, conventions are optional, but it seems like a good one to me.
I haven't quite into the groove with Pathom yet. A lot of it, for me, seems to come down to properly naming things. Usually when I have an a-ha moment, I end up renaming something, it all becomes simpler, and I realize I over-complicated the heck out of things in the first place.
well, you can always add another xxxx.ordered-item
file/ns and go from there if it's worth it to you. I get what you mean though. If you aren't super strict about a particular naming convention you could also go with :com.example.model.account/ordered-item-names
.
That's exactly what I have right now. Got things to a working stage and just trying to do a little cleanup. The account/ordered-item-names
approach feels sloppy in my code.
I end up with a bunch of account/ordered-item-x
. Makes me think I'm not using Pathom to its potential or my stuff just isn't organized properly. Probably a bit of both 😛
Do you have more attributes / keywords like this? I think once you've aggregated a number of these it's easier to get a sense of what "feels correct" for you. It's probably not worth it to spend many hours thinking about a single keywords place
> I end up with a bunch of `account/ordered-item-x`. Yeah that sounds like you're not using pathom like you should
your ordered-items on account
are a ref to another entity right?
So the account/ordered-items attribute or resolver should just return their ids and all other attributes should reside in an ordered-items
namespace. pathom will figure things out for you
So that means 3 namespaces
(ns bla.account)
(defattr orders :bla.account/orders :ref ...)
(defresolver ordered-items ....)
(ns bla.order)
(defattr order-id...)
(defattr ordered-items...)
(ns bla.item)
(defattr item-id ...)
(defattr item-name ...)
You can think of the ordered-items
resolver as a helper for pathom, so you can call the resolver with an order-id, then go straight to your database, fetch all the items and return them (or just their id's, depending on what you want to do)
This resolver could then be used like this:
[{[:bla.account 123]
[{:bla.account/ordered-items [:item/name ...]}]
I probably got the syntax wrong, but you get the ideaYeah, once it gets the ids it should be able to walk the graph to the rest of the requested attributes without needing specific resolvers.
I think it makes sense. Thanks @U012ADU90SW. I'll try to factor things down a bit tomorrow and reflect on why I made it so complicated...
Even so, you don't actually need a resolver if you already have a :ref
attribute to orders
in place, but your query would look more involved