This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-16
Channels
- # autochrome-github (17)
- # aws (6)
- # babashka (19)
- # beginners (42)
- # bristol-clojurians (1)
- # calva (1)
- # cider (7)
- # clara (1)
- # clj-kondo (6)
- # cljdoc (17)
- # cljs-dev (5)
- # clojars (23)
- # clojure (93)
- # clojure-europe (20)
- # clojure-italy (28)
- # clojure-nl (13)
- # clojure-sanfrancisco (1)
- # clojure-uk (50)
- # clojuredesign-podcast (5)
- # clojurescript (90)
- # core-async (8)
- # datomic (23)
- # duct (3)
- # emacs (10)
- # figwheel-main (1)
- # fulcro (1)
- # malli (1)
- # meander (22)
- # off-topic (12)
- # pathom (57)
- # reitit (4)
- # remote-jobs (5)
- # shadow-cljs (5)
- # sql (8)
- # tools-deps (3)
it depends on how much you want to hammer your db, I have resolvers that compose a fat query and return most of the data already to minimize back and forth
(utils/request-eql '[{[:shop/uuid #uuid"00000000-0000-0000-0000-000000000000"] [* :shop/name]}])
return
#:shop{:uuid #uuid"00000000-0000-0000-0000-000000000000",
:name "redshop",
:engine "atomstore",
:config {:foo "bar"},
:updated_at #inst"2020-03-15T23:03:19.353-00:00",
:created_at #inst"2020-03-15T23:03:19.353-00:00"}
but
(utils/request-eql '[{[:shop/uuid #uuid"00000000-0000-0000-0000-000000000000"] [*]}])
return
#:shop{:uuid #uuid"00000000-0000-0000-0000-000000000000"}
For resolver:
(pc/defresolver get-shop [env {:shop/keys [uuid]}]
{::pc/input #{:shop/uuid}
::pc/output [:shop/uuid :shop/name :shop/engine :shop/config]}
(shop-biz/get-shop uuid))
How to get ALL values?
I was trying also
(utils/request-eql '[[:shop/uuid #uuid"00000000-0000-0000-0000-000000000000"]])
if you just supply *
no resolvers will be called, hence you only get what you provided for base entity
there is no way to say I want all direct outputs (or n-levels deep) from this attribute that I provided
How does it work here https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/connect/resolvers.html#GlobalResolvers ?
for [{::latest-product [*]}]
I got
{::latest-product
{:product/id 1,
:product/title "Acoustic Guitar",
:product/price 199.99}}
also output make me confuse because:
::pc/output [:shop/uuid :shop/name :shop/engine :shop/config]}
can return
#:shop{:uuid #uuid"00000000-0000-0000-0000-000000000000",
:name "redshop",
:engine "atomstore",
:config {:foo "bar"},
:updated_at #inst"2020-03-15T23:03:19.353-00:00",
:created_at #inst"2020-03-15T23:03:19.353-00:00"}
anyway that is for exploratory cases and shouldn’t be the way you use Pathom in real code
(pc/defresolver get-shop [env {:shop/keys [uuid]}]
{::pc/input #{:shop/uuid}
::pc/output [:shop [:shop/uuid :shop/name :shop/engine :shop/config]]}
{:shop (shop-biz/get-shop uuid)})
(pc/defresolver get-shop [env {:shop/keys [uuid]}]
{::pc/input #{:shop/uuid}
::pc/output [:shop/uuid :shop/name :shop/engine :shop/config]}
(shop-biz/get-shop uuid))
Do you see any pros / cons between this 2 ver.?
So return data in :shop
vs directlyas people described, flat is better, but just a hint, the first example is missing the map {}
to make the join between :ship
and the nested properties
Keep your resolvers flat, reserve nesting for joins (when you need to return multiple maps/etc. like {:user/friends [:user/id]}
)
hmm after all I think get-shop
doesn’t make sense. get-shops
is probably what I want.
Do you use create-shop
/ create-shops
?
I know this questions sounds dump, but pathom in my feeling gives possibilities of different approaches which can be still simple
id say it depends on your use cases. Do you have scenarios where you bulk create “shops”
probably not, but I would like to keep the same rule for all queries. plural or singular, but not both.
yeah, you might just want to experiment a bit, especially for my mutations, i tend to try to let them reflect the ‘commands’ in my domain. nice thing is that if you follow the guidance of doing most of the work in separate functions that your resolvers call, it’s a little easier to come up with composable bits that are easier to leverage in whatever resolver approach you settle on
In my experience, there is no create
operation in any system
create-user
usually will create user
, session
, message
buy-item
will create cart
itemInCart
...
that CRUD
thing simply don't exists nor help
another thing i’ve found is that resolver names are themselves less of a big deal, for instance, i’ve got some code that I use to auto-generate some of them, the real deal is what they’re contributing to the resolver graph.
sure, go with that, and see how it works out for you.. and like i said, if your resolvers and mutations are delegating most of their work to helpers, say a create-many-items
shouldn’t be a big lift if you end up needing it
i’ve had situations where pretty much all of the ‘app driven’ stuff was more or less your model, create-one
but later i needed some bulk import capability. So just whipped up some code that used my create-one helper functions for a bulk mport process that was run by ops in the background
BTW what is your pattern to get all items vs selected items?
(utils/request-eql [{[:shop/uuids #{}] [:shops]}])
I am thinking about send empty uuids as “get all”@kwladyka take a look at https://www.infoq.com/presentations/domain-driven-architecture/
in my case, i’m using datomic on the backend, and this little bit of meta/domain modeling code i wrote, so those resolvers by and large just get generated. I’ve found that the cases where i need one v many tend to not really overlap too much so by applying consistently i’m generally ok.
yeah that’s the beauty of it, you can do almost whatever you want. though your mileage will of course vary. One thing you might want to play around with in your approach is passing whatever params you need (paging, limits, whatever).
(let [shop #:shop{:uuid #uuid"11111111-1111-1111-1111-111111111111"
:name "test shop"
:engine "engine"
:config "{\"abc\": \"def\"}"}]
(is (= shop
(utils/request-eql [{'(shop/update shop)
[:shop/uuid :shop/name :shop/engine :shop/config]}]))
"update shop"))
How do you achieve
'(shop/update shop)
I mean I want to call mutation, but I want to have shop
from let
pr-str
i think that is the default method to generate a string from edn
but usually we use transit
once it runs on browser
query
(let [shop #:shop{:uuid #uuid"11111111-1111-1111-1111-111111111111"
:name "test shop"
:engine "engine"
:config {:abc "def"}}]
(utils/request-eql [{`(shop/update ~shop) [:shops [:shop/uuid :shop/name :shop/engine :shop/config]]}]))
response
#:shop{update
{[:shop/uuid :shop/name :shop/engine :shop/config]
#:shop{:uuid :shop/name},
:shops
[#:shop{:uuid #uuid "11111111-1111-1111-1111-111111111111",
:name "test shop",
:engine "engine",
:config {:abc "def"},
:updated_at #inst "2020-03-16T20:33:21.279-00:00",
:created_at #inst "2020-03-16T20:18:03.964-00:00"}]}}
^ what #:shop{:uuid :shop/name}
doing here?
defs
(pc/defmutation update-shop [env params]
{::pc/sym 'shop/update
::pc/params #{:shop/uuid :shop/name :shop/engine :shop/config}
::pc/output [:update]}
(shop-biz/update-shop params)
{:shop/uuids #{"11111111-1111-1111-1111-111111111111"}})
(pc/defresolver get-shops [env {:shop/keys [uuids]}]
{::pc/input #{:shop/uuids}
::pc/output [:shops [:shop/uuid :shop/engine]]}
{:shops (shop-biz/get-shops uuids)})
I have to say after all new doc makes me very confused. I have no idea how to use pathom. Maybe I will try to read old doc tomorrow.