This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-03
Channels
- # announcements (2)
- # atom-editor (1)
- # babashka (6)
- # beginners (49)
- # calva (39)
- # clj-kondo (20)
- # clojure (41)
- # clojure-australia (1)
- # clojure-europe (33)
- # clojure-germany (8)
- # clojure-italy (2)
- # clojure-losangeles (1)
- # clojure-norway (3)
- # clojure-spec (5)
- # clojure-uk (48)
- # clojurescript (147)
- # conjure (24)
- # core-logic (1)
- # datahike (6)
- # datomic (14)
- # emacs (10)
- # events (1)
- # fulcro (11)
- # garden (1)
- # girouette (2)
- # honeysql (16)
- # jobs (3)
- # kaocha (3)
- # malli (5)
- # meander (7)
- # off-topic (49)
- # pathom (50)
- # portal (3)
- # reagent (4)
- # reitit (7)
- # rewrite-clj (3)
- # ring (3)
- # sci (4)
- # shadow-cljs (46)
- # spacemacs (10)
- # sql (3)
- # tools-deps (57)
In pathom3
, there is some function that given a an env
and a query
it returns which inputs are required to resolve this function?
for example:
- env: (pci/register [(single-attr-resolver :a :b inc)])
- query: [:b]
- returns: [:a]
that's the planner
it wont tell you directly that, but you can create a plan and infer this data from it
@wilkerlucio i am testing the batch resolvers on pathom3 and found a problem. If the “parent” resolver of the batch resolver returns a seq you get a 1. Unhandled java.lang.ClassCastException
this is a way to reproduce it:
(def db {:contracts {"contract-1" {::contract/id 1
::contract/code "contract-1"
::contract/name "the name"}}
:positions {1 '({::position/units 10
::instrument/fund {::fund/id 1}}
{::position/units 20
::instrument/fund {::fund/id 2}})}
:funds {1 {::fund/code "fund 1"}
2 {::fund/code "fund 2"}}})
(pco/defresolver contract-resolver [{::contract/keys [code]}]
{::pco/output [::contract/id ::contract/code ::contract/name]}
(get-in db [:contracts code]))
(pco/defresolver position-resolver [{::contract/keys [id]}]
{::pco/output [{::contract/positions [::position/units {::instrument/fund [::fund/id]}]} ]}
{::contract/positions (get-in db [:positions id])})
(pco/defresolver fund-resolver [input]
{::pco/input [::fund/id]
::pco/output [::fund/code]
::pco/batch? true}
(clojure.pprint/pprint
{:in input
:res (map #(get-in db [:funds (::fund/id %)])
input)})
(map #(get-in db [:funds (::fund/id %)])
input))
(p.eql/process
(pci/register [contract-resolver position-resolver fund-resolver])
[{[::contract/code "contract-1"] [::contract/name {::contract/positions [::position/units {::instrument/fund [::fund/code]}]}]}])
everything works perfectly if db is changed to
(def db {:contracts {"contract-1" {::contract/id 1
::contract/code "contract-1"
::contract/name "the name"}}
;;notice that positions are now a vec
:positions {1 [{::position/units 10
::instrument/fund {::fund/id 1}}
{::position/units 20
::instrument/fund {::fund/id 2}}]}
:funds {1 {::fund/code "fund 1"}
2 {::fund/code "fund 2"}}})
@jmayaalv yes, that's a limitation, I think the right approach at this time is to give a better error message
the issue is that batch needs to be able to navigate, it would be possible to make lists work, but at some processing cost (because I can't update-in a list, but I can in a vector)
can you open an issue for it?
I'm struggling to surface resolver exceptions in Pathom3. What attr should I provide to pcrs/get-attribute-error
to get the internal error exception?
(pco/defresolver throws [{:a/keys [input]}]
(throw (Exception. "Internal error"))
{:a/output (str "echoing " input)})
(-> (p.eql/process (-> [throws] (pci/register))
[{[:a/input "hello"] [:a/output]}])
(meta)
::pcr/run-stats
(psm/smart-run-stats)
(pcrs/get-attribute-error :a/output))
Under the latest Pathom3 commit, get-attribute-error itself returns
{:com.wsscode.pathom3.connect.runner.stats/node-error-type :com.wsscode.pathom3.connect.runner.stats/node-error-type-unreachable
:com.wsscode.pathom3.connect.runner/node-error #reveal/error{:via [{:type clojure.lang.ExceptionInfo
:message "Can't find a path for :a/output"
:data {:com.wsscode.pathom3.attribute/attribute :a/output}
:at [com.wsscode.pathom3.connect.runner.stats$attribute_error__30270 invokeStatic "stats.cljc" 73]}]
:trace [[com.wsscode.pathom3.connect.runner.stats$attribute_error__30270 invokeStatic "stats.cljc" 73]
[com.wsscode.pathom3.connect.runner.stats$attribute_error__30270 invoke "stats.cljc" 51]...}
hello @markaddleman, the issue is that you are looking for the error in the wrong map
errors and stats are per entity (each map in the response gets its own)
this should work:
(-> (p.eql/process (-> [throws] (pci/register))
[{[:a/input "hello"] [:a/output]}])
(get [:a/input "hello"])
(meta)
::pcr/run-stats
(psm/smart-run-stats)
(pcrs/get-attribute-error :a/output))
ah ha
One more thing: Is there a convenient & performant way of checking if any attributes have errors?
yes, in the run stats, there is a key that says all the nodes with errors
My desired exception handling policy is to throw an exception if any resolver throws so I'm writing my own query function to handle this
one thing to consider is that its possible to have a failed node, but still a fully successful response, this can happen if there are multiple paths for something (a OR node), some path fails, other path succeed
in this case, you will have an error, but still a complete response
Understood. In my case, there is no OR but I'll keep this is mind
perfect
I think you can learn a lot about checking the sources for the attribute-errors-plugin: https://github.com/wilkerlucio/pathom3/blob/master/src/main/com/wsscode/pathom3/connect/built_in/plugins.cljc#L10-L40
perfect! Thank you
Wondering what you think about resolver input maps being smart-maps? My app gets a client query, processed by pathom as EQL and many times it is convenient to pass the input around to different functions that might need to compute things for which resolvers already exist.
that can kill efficiency in a sense, ideally you can just write more resolvers and always be as specific as possible about your requirements, this is the way to maximize the utility of how pathom can optimize your code paths to fulfill data needs
because if you give them as smart maps, you delay the point in which you know what you need
so each time you read, pathom has to go over the planning and running process again
while if you do in a single go, pathom can plan once, and with more information makes it more efficient (because it can optimize repeated paths and stuff like that)
"each time you read" - This means get
operations on the smart map?
doing a single query is much likely going to be faster than lazy loading one attribute at a time
I had that situation with Pathom Viz, I was using smart maps to compute trace data
Fair enough. Although, in my case, I think the only performance difference is Pathom's overhead to compute the plan. No matter what, I'm going to have to compute the result I care about. The only issue is whether the computation occurs as part of a smart-map get
or as a direct function call
I was feeling some perf hit, and switch over to a pre-defined query in EQL, that got around 8x faster (because there was a lot of collection items, in those cases the usage of smart maps to do one attr a time adds up)
what I'm telling you is mostly about my perf expectations, but I like to encourage you to play around with a mixed approach, and Pathom totally supports that
you can write a plugin to make this happen
Oh, that's a good idea. I had planned on each resolver wrapping input
in a smart map but a plugin is much more convenient
using the wrap-resolve
hook, there, you can wrap the resolver call by transforming the input in a smart map, them you get what you asked for
Perfect
This whole conversation brings to mind something I've been wondering about: Given smart-maps, what is the right balance between function calls on maps vs get
operations & resolvers
and I'm curious how this goes, would to learn more about what happens after some time doing that 🙂
function calls on maps?
I mean a function that takes a map as input
that's the design part, depends how much you want to delegate to pathom
or what "entry points" you wanna give to the system
Here is my latest thought: Because Cursive does a much better job of navigating among function defs and function calls, my sanity prefers function calls over smart-map resolvers and keys. It's just much easier to reverse engineer what's going on. Perhaps when I become more familiar with Pathom Viz and other debugging tools, I'll change my mind.
That's not to say I don't think smart-maps & resolvers have their place... They definitely do. It's just that when I don't have a compelling reason one way or the other, I'll stick to fns