Fork me on GitHub
#pathom
<
2022-06-08
>
roklenarcic12:06: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?

wilkerlucio18:06:24

1. no, because optionality is always on the demand side (input) never on the output

wilkerlucio18:06:39

2. not sure if I understand, if you wanna say you dont have the value, dont output the key

roklenarcic18:06:40

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

wilkerlucio19:06:27

can you send a repro that demonstrates the unexpected behavior?

roklenarcic19:06:09

not as much unexpected behaviour as missing feature

roklenarcic13:06:23

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?

wilkerlucio18:06:37

are you on the latest pathom3? the last case there was something I remember fixing recently

wilkerlucio18:06:21

if you are, please send a repro case and I can take a closer look

roklenarcic18:06:53

updated to the latest, still same problem

roklenarcic19:06:15

(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)]}])
  )

roklenarcic19:06:33

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)]}])
  )

roklenarcic19:06:11

so if I reduce resolver path by 1level it works

wilkerlucio15:06:41

thanks for the demos, I'll quite busy today but I'll have a closer look at it tomorrow

wilkerlucio01:06:07

hello @U66G3SGP5, sorry the long delay, I have tried now the examples, but they seem to behave correctly to me

wilkerlucio01:06:19

if you use strict mode, all the asks work fine (no exception thrown)

wilkerlucio01:06:50

on lenient mode, you get the error detail because you will always get all errors there, but in terms of result they are equivalent