Fork me on GitHub
#pathom
<
2022-03-27
>
geraldodev15:03:24

(pco/defresolver employee->manager [{:keys [employee/manager_id]}]
  {::pco/input [:employee/manager_id]
   ::pco/output [{(pco/? :employee/manager) [:employee/employee_id]}]}
  {:employee/manager (when manager_id {:employee/employee_id manager_id})})
Today I've learnt two things : One is that the optional atributte (pco/? attr) must be defined at attribute level. I was mistakenly calling the entire output shape with (pco/? {...}). The second thing and that is not intuitive for me is I need to return the {:employe/manager nil} in case of the attribute being nil. I was mistakenly returning nil instead of the map with the nil value and it was getting "Required attributes missing: [:employee/manager] " I wonder required by whom , the calling query ? Because I've already marked it as optional. I also learnt that I can mark the attribute as optional at the calling query, but I don't think it's a good solution.

wilkerlucio15:03:23

hello Geraldo, marking output things as optionals have no meaning, the requirement of something is always on the loader side (the input), outputs are are always "optional by default", the requirement is always on the demanding side (which may flag it as optional)

wilkerlucio15:03:34

so when it says Required attributes missing: [:employee/manager] it means some part of your query requested that as required (which is the default, unless you mark something as optional, that is true both for resolver inputs, as for your actual query, which you can also mark things as optional if that's the case)

wilkerlucio15:03:43

that makes sense?

geraldodev19:03:22

;; no manager
  (p.eql/process
    (pci/register (user/db-hr-map) index)
    [{[:employee/employee_id 100] [:employee/employee_id :employee/first_name :employee/salary
                                   {:employee/manager [:employee/first_name]}]}])
I've read again the optional inputs documentation with the context of your commentary and it really makes the case of inputs like your are teaching me. It's very hard to put on words how an algorithm is working. :employee/manager and employee/first_name are output properties and both are declared on the query, but for :employee/manager I have to return an attribute with a null value and when that is the case there is no :employee/first_name and no message of it being required. What I'm experiencing is output properties are optional and as long the engine does not turn the attention for it in a resolver.

geraldodev19:03:22

Thank you for teaching us.

🙏 1