Fork me on GitHub
#pathom
<
2020-03-17
>
pithyless10:03:07

Hej @kwladyka 👋 Long time no see. 😉 I've attached some notes on how I think about resolvers:

👍 8
kwladyka13:03:48

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 😉 )

myguidingstar20:03:37

@wilkerlucio is it possible to apply the batch transformer to a dynamic resolver?

kwladyka21:03:34

(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?

kwladyka21:03:06

I feel :com.wsscode.pathom.core/not-found is a bad idea

pithyless21:03:38

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

👍 4
kwladyka22:03:11

(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?

kwladyka22:03:09

so…

:shop/uuid #uuid"11111111-1111-1111-1111-111111111111"
if I use #uuid in EQL query I have to return str. But if I use string in EQL query
:shop/uuid "11111111-1111-1111-1111-111111111111"
I can return #uuid or str This is a little unpredictable