pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
eoliphant 2021-02-18T02:19:53.296600Z

Will dbl check the docs, etc

2021-02-18T09:38:16.299900Z

We got asked today the possibility to expose our pathom api as a graphql api. i know this has been discussed several times and there are attempts like https://github.com/denisidoro/graffiti but do you think it would make sense to relay on pathom3's smart maps as lacinia resolvers? so basically we would create the graphql schema define the root queries attaching resolvers that use smartmaps

wilkerlucio 2021-02-18T12:13:07.301800Z

I would avoid smart maps for this use case, doing large queries one attribute at a time isnt very efficient, and some queries will pay more than others

wilkerlucio 2021-02-18T12:13:25.302600Z

I think there is some work to be done, like Grafitti to improve that story

wilkerlucio 2021-02-18T12:14:27.303800Z

not on my radar at this time, but I can help if anyone wants to try that direction

markaddleman 2021-02-18T19:12:32.304Z

markaddleman 2021-02-18T19:12:49.304600Z

(please disregard the namespace name - I'm not sure this is a bug 🙂 )

markaddleman 2021-02-18T19:14:53.306800Z

I have a resolver called "dimension-attributes" which can produce an array of raw data which another resolver formats into something - in this example, that formatting has trivial logic in the id-event-level resolver. Finally, I have a resolver field-list which reformats the data into something suitable for the pivot table UI widget

markaddleman 2021-02-18T19:15:24.307600Z

The dimension-attributes resolver can produce an empty array

markaddleman 2021-02-18T19:16:33.309Z

When the dimension-attributes resolver produces an empty array, the reformatting resolver (field-list) is not invoked and, so, the field-list resolver is not invoked. This results in the wrong data sent to the UI

markaddleman 2021-02-18T19:17:01.309500Z

I've tried various combinations of pco/? but I cannot find the right combination to get the result I'm looking for.

markaddleman 2021-02-18T19:17:07.309700Z

Am I going about this the wrong way?

2021-02-18T19:37:08.309800Z

Thanks for the input wilker. It's probably something we will need to implement at some point. I can start looking at it, is the graffiti code a good place to start ?

dehli 2021-02-18T23:46:24.310400Z

the problem is when you return an empty array you’re not returning those keys (`:key`, :some , and :data) so pathom won’t be able to invoke the id-event-level resolver (which is how your field-list’s attribute-id input can be fulfilled). what would you like the response of (:>/input {:key "empty"}) to be?

dehli 2021-02-18T23:52:50.311Z

Instead of returning a vector would this work?

(pco/defresolver dimension-attributes [{:keys [key]}]
  {::pco/input  [:key]
   ::pco/output [{:attributes/dimensions [:key :some :data]}]}
  {:attributes/dimensions (when (not= key "empty")
                            {:key "key"
                             :some "a"
                             :data "b"})})

(pco/defresolver id-event-level [input]
  {::pco/input [(pco/? :key) (pco/? :some) (pco/? :data)]}
  {:attribute/id input})

;; Keep the rest the same
When you return an empty array, there’s nothing for pathom to iterate on which is the real issue with your original code (and why using a combination of (pco/?) probably wasn’t working).