This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-17
Channels
- # announcements (7)
- # babashka (56)
- # beginners (114)
- # bristol-clojurians (4)
- # calva (22)
- # cider (7)
- # clara (1)
- # clj-kondo (17)
- # cljs-dev (1)
- # clojure (93)
- # clojure-europe (8)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-uk (79)
- # clojuredesign-podcast (18)
- # clojurescript (108)
- # code-reviews (6)
- # cursive (3)
- # data-science (16)
- # datomic (151)
- # duct (7)
- # emacs (10)
- # events (1)
- # fulcro (76)
- # luminus (8)
- # off-topic (3)
- # other-lisps (2)
- # pathom (8)
- # re-frame (5)
- # reitit (8)
- # schema (9)
- # shadow-cljs (37)
- # specter (3)
- # sql (17)
- # tree-sitter (2)
- # yada (9)
Hej @kwladyka 👋 Long time no see. 😉 I've attached some notes on how I think about resolvers:
hello @pithyless 🙂 Very long time ! Thanks for example. I will relocate to Wrocław soon. Give me some news from your live 🙂 (maybe not on this channel 😉 )
@wilkerlucio is it possible to apply the batch transformer to a dynamic 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))
(utils/request-eql [{[:shop/uuid "99999999-9999-9999-9999-999999999999"] [:shop/uuid :shop/name :shop/engine :shop/config]}])
=>
#:shop{:uuid "99999999-9999-9999-9999-999999999999",
:engine :com.wsscode.pathom.core/not-found,
:name :com.wsscode.pathom.core/not-found,
:config :com.wsscode.pathom.core/not-found}
What is the best practice? Can I return clear information when the shop is not found? Or is good like it is for EQL?If you return just {:shop/uuid ".."}
, then Pathom will try a different resolver that has :shop/engine
. So, if you're sure that there is no :shop/engine
for this case, you want to return something.
You can e.g. return {:shop/engine nil}
, but then you need to be sure that whoever is parsing the result will be ok with handling a nil
engine correctly.
You can also return {:shop/engine :com.wsscode.pathom.core/not-found}
and then use a parser plugin (e.g. elide-special-outputs-plugin
) to remove the not-found values before returning the result to the client.
https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/plugins.html#_built_in_plugins
https://github.com/wilkerlucio/pathom/blob/master/src/com/wsscode/pathom/core.cljc#L721-L722
(pc/defmutation update-shop [env params]
{::pc/sym 'shop/update
::pc/params #{:shop/name :shop/engine :shop/config}
::pc/output [:shop/uuid]}
(shop-biz/update-shop params)
(-> (select-keys params [:shop/uuid])
(update :shop/uuid str))
{:shop/uuid #uuid"11111111-1111-1111-1111-111111111111"})
I found resolvers are not called with #uuid
but works without.
(pc/defresolver get-shop [env params]
{::pc/input #{:shop/uuid}
::pc/output [:shop/name :shop/engine :shop/config]
::pc/transform pc/transform-batch-resolver}
(println "foo" (shop-biz/get-shops (set (map :shop/uuid params))))
(shop-biz/get-shops (set (map :shop/uuid params))))
I don’t see println
with #uuid
.
Why?