Fork me on GitHub
#pathom
<
2022-06-16
>
JAtkins10:06:13

Hi all, Currently I’m working with entity missing exceptions for our domain model. Theoretically, it’s pretty simple to add :entity/accessible? keys to each of our xxx-by-id resolvers, but it’d be nice to instead extend the ::pathom-runner/attribute-error map. The intended data shape was

{:xxx/id ... ;; Entity map

 ::pathom-runner/attribute-error {:xxx/id :unreachable}}
However, no plugin in pathom allows extending attribute-error in this way, except for the root run node plugins as far as I can tell. Is this data shape possible with plugins? Neither ::pathom-runner/wrap-resolver-error nor ::pathom-error/wrap-attribute-error are capable of making this shape.

wilkerlucio20:06:57

so you wanna change the format of the error, let me take a look to see if I can stop some other extension point, otherwise we may add one more

wilkerlucio20:06:33

just by looking at the code seems like ::wrap-attribute-error should be able to update that, no? I can give a try here to double check

wilkerlucio20:06:15

I have an example here, please let me know if its sufficient:

wilkerlucio20:06:16

(ns com.wsscode.pathom3.demos.attribute-error-wrap
  (:require [com.wsscode.pathom3.connect.operation :as pco]
            [com.wsscode.pathom3.connect.indexes :as pci]
            [com.wsscode.pathom3.interface.eql :as p.eql]
            [com.wsscode.pathom3.plugin :as p.plugin]))

(pco/defresolver error [{::keys []}]
  {:foo (throw (ex-info "lala" {}))})

(def env
  (-> {:com.wsscode.pathom3.error/lenient-mode? true}
      (pci/register error)
      (p.plugin/register
        {::p.plugin/id 'error-thing
         :com.wsscode.pathom3.error/wrap-attribute-error
         (fn [attr-error]
           (fn [entity k]
             (let [err (attr-error entity k)]
               (:com.wsscode.pathom3.error/cause err))))})))

(comment
  (p.eql/process env [:foo]))

wilkerlucio20:06:59

result:

=>
{:com.wsscode.pathom3.connect.runner/attribute-errors {:foo :com.wsscode.pathom3.error/node-errors}}

wilkerlucio22:06:09

taking a second read I see I may have misinterpreted the issue. is correct that what you want is to affect the error on the parent level according to some definition inside :xxx/id?

JAtkins08:06:46

So, it’s a bit more complicated unfortunately. I’d like to use an ident join to perform root loads in fulcro, but if the entity is missing return in the error key :unreachable

{[:xxx/id ...]  
  {:xxx/id ... ;; Entity map

   ::pathom-runner/attribute-error {:xxx/id :unreachable}}}
But, since :xxx/id is not being resolved by the planner, it’s not an option for the wrap-attribute-error plugin.

roklenarcic20:06:48

looking at pathomviz useage docs I think there’s a step missing.. I think you need to expose parser via an endpoint that uses Transit, am I right?

wilkerlucio20:06:12

depends, if you wanna use the HTTP connection yes, but otherwise you should use the pathom viz connector: https://github.com/wilkerlucio/pathom-viz-connector/

wilkerlucio20:06:26

its recommended to use the connector during dev, the http is more targeted for staging/prod environments

roklenarcic08:06:18

it runs now, but I’d love to fix #object[Object [TaggedValue: unknown, #clj-time/date-time “2020-02-13T10:20:14.000Z”]],

wilkerlucio14:06:32

this is the same issue with Fulcro Inspect, because they run their own environment it would have to know about specific libraries like clj-time to handle that

wilkerlucio14:06:47

so it uses the generic TaggedValue for custom types

wilkerlucio20:06:41

and to everyone here, sorry I'm a bit slow these weeks, I'm on vacation and trying to stay away from computer a bit, I'll be fully back by June 27 🙂

12
🍻 3
hammock 1
🍷 1