Fork me on GitHub
#pathom
<
2022-03-16
>
danieroux14:03:40

Lenient mode in Pathom3, using boundary-interface** and serializing to Transit: :com.wsscode.pathom3.error/node-exception fails to serialize. Do we need to remove that from the result before sending over the wire?

danieroux14:03:51

(ns pathom-boundary-interface-errors
  (:require
    [cognitect.transit :as transit]
    [com.wsscode.pathom3.connect.operation :as pco]
    [com.wsscode.pathom3.connect.indexes :as pci]
    [com.wsscode.pathom3.interface.smart-map :as psm]
    [com.wsscode.pathom3.interface.eql :as p.eql]
    [com.wsscode.pathom3.connect.built-in.resolvers :as pbir]
    [com.wsscode.pathom3.error :as p.error])
  (:import
    [ ByteArrayOutputStream ByteArrayInputStream]))

(def indexes
  (pci/register
    [(pbir/constantly-fn-resolver ::throw-error (fn [_] (throw (ex-info "Error" {}))))]))

(def pathom
  (p.eql/boundary-interface
    (merge
      indexes
      {::p.error/lenient-mode? true})))

(defn ->transit
  [form]
  (let [out (ByteArrayOutputStream. 4096)
        writer (transit/writer out :json)]
    (transit/write writer form)
    (.toString out)))

; :com.wsscode.pathom3.error/exception cannot be serialized to Transit
; Throws:
; Not supported: class clojure.lang.ExceptionInfo
(->transit (pathom [::throw-error]))

wilkerlucio14:03:43

what version are you using? I see something different on my end, but there is also a bug I notice

wilkerlucio14:03:00

but on my end, the bug is that if you have ::p.error/lenient-mode? true the boundary interface will return a blank output (on latest pathom)

wilkerlucio14:03:21

instead of using at the env level, you can set it on the request level as well

wilkerlucio14:03:30

(pathom {:pathom/eql [::throw-error]
                      :pathom/lenient-mode? true})

wilkerlucio14:03:40

right now, sending it there works, I'm going to fix pathom in a bit

danieroux14:03:14

Currently on v2022.01.09-alpha

danieroux14:03:20

So the Right Thing to get things over the wire is to remove any :com.wsscode.pathom3.error/node-exception from the result?

wilkerlucio15:03:36

you should bump Pathom, you are using an old version

wilkerlucio15:03:48

in the new versions it already does some error processing that makes it suitable to go over the wire

wilkerlucio15:03:36

I'm finishing the fix to the latest, should be out today

wilkerlucio15:03:06

current latest is 2022.03.07-alpha

danieroux08:03:08

Thank you @U066U8JQJ! We have errors flowing over the wire

wilkerlucio00:03:25

@danie just released 2022.03.17-alpha which fixed the lenient mode from env with boundary interface

danieroux17:03:16

Works like a charm, thank you @U066U8JQJ