This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-08
Channels
- # announcements (2)
- # asami (2)
- # babashka (7)
- # beginners (59)
- # cider (12)
- # cljdoc (1)
- # cljs-dev (18)
- # clojure (23)
- # clojure-europe (15)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-uk (5)
- # clojured (16)
- # clojurescript (22)
- # core-typed (8)
- # cursive (3)
- # datomic (24)
- # events (2)
- # fulcro (4)
- # gratitude (1)
- # helix (13)
- # hoplon (18)
- # integrant (2)
- # introduce-yourself (1)
- # jobs-discuss (1)
- # joyride (5)
- # minecraft (1)
- # off-topic (76)
- # pathom (18)
- # podcasts-discuss (8)
- # polylith (11)
- # remote-jobs (4)
- # rewrite-clj (22)
- # sci (4)
- # shadow-cljs (152)
- # sql (4)
- # tools-build (26)
- # tools-deps (34)
1. Does specifying pco/?
in output vector do anything?
2. If I return ::missing
for some/id
that gets pushed into the next resolver as a value, how would I short-circuit that? Use pco/transform
to wrap all handlers in some code that handles this?
1. no, because optionality is always on the demand side (input) never on the output
2. not sure if I understand, if you wanna say you dont have the value, dont output the key
right but if I dont output the key I get an error. This is kinda a running problem I’ve got with optional stuff. Sometimes when outputting a list of items that may have 1 optional attribute I want to filter based on whether the optional attribute was requested or not (and so avoid the error by returning just the items with the optional attribute present).
can you send a repro that demonstrates the unexpected behavior?
not as much unexpected behaviour as missing feature
The weird part of the optional value story is what happens when you specify some derived attributes as optional. I have a resolver user/id => [(pco/? :github/id)]
and a resolver github/id => [github/email github/username]
Now the query `
[{[:user/id 11] [(pco/? :github/id)]}]
works like you’d expect for a user without github, {[:user/id 11] {}}
Then I try to add another data point:
[{[:user/id 11] [(pco/? :github/id) (pco/? :github/email)]}]
And I’ll get All paths from an OR node failed.
. So optional values are only really useful for “leaf” attributes?are you on the latest pathom3? the last case there was something I remember fixing recently
if you are, please send a repro case and I can take a closer look
updated to the latest, still same problem
(pco/defresolver res1 [_]
{::pco/output [{:user/all [:user/id]}]}
{:user/all (map #(hash-map :user/id %) (range 10))})
(pco/defresolver res2 [{:user/keys [id]}]
{::pco/output [:github/id]}
(if (even? id) {:github/id id}))
(pco/defresolver res3 [{:github/keys [id]}]
{::pco/output [:github/username]}
{:github/username (str "user " id)})
(def env
(-> {::p.error/lenient-mode? true}
(pcp/with-plan-cache)
(pci/register [res1 res2 res3])))
(defn ask [tx]
(p.eql/process env tx))
(comment
;; works
(ask [{:user/all [:user/id (pco/? :github/id)]}])
;; doesn't work, error
(ask [{:user/all [:user/id (pco/? :github/username)]}])
)
however it works if I do the following:
(pco/defresolver res1 [_]
{::pco/output [{:user/all [:user/id]}]}
{:user/all (map #(if (even? %) {:user/id % :github/id %} {:user/id %}) (range 10))})
(pco/defresolver res3 [{:github/keys [id]}]
{::pco/output [:github/username]}
{:github/username (str "user " id)})
(def env
(-> {::p.error/lenient-mode? true}
(pcp/with-plan-cache)
(pci/register [res1 res3])))
(defn ask [tx]
(p.eql/process env tx))
(comment
;; works
(ask [{:user/all [:user/id (pco/? :github/id)]}])
;; works
(ask [{:user/all [:user/id (pco/? :github/username)]}])
)
so if I reduce resolver path by 1level it works
thanks for the demos, I'll quite busy today but I'll have a closer look at it tomorrow
hello @U66G3SGP5, sorry the long delay, I have tried now the examples, but they seem to behave correctly to me
if you use strict mode, all the asks work fine (no exception thrown)
on lenient mode, you get the error detail because you will always get all errors there, but in terms of result they are equivalent
makes sense?