Fork me on GitHub
#pathom
<
2021-08-12
>
caleb.macdonaldblack00:08:39

Why does this happen in Pathom3?

(pco/defresolver foobar []
  {::pco/output [:id :name]}
  {:id 1 :name "foobar"})

((p.eql/boundary-interface
   (pci/register [foobar]))
 {:pathom/eql [:id :name] :pathom/entity {:id 0}})

=> {:id 0, :name "foobar"}
It feels odd that that id is my input by my output is also included.

caleb.macdonaldblack00:08:21

I was writing a test and was not expecting this behaviour. I feel like it could introduce bugs where the wrong resource is returned but it looks good because the id matches now

wilkerlucio01:08:35

@caleb.macdonaldblack this happens because your resolver doesn't require any input, so this makes :id and :name available globaly

wilkerlucio01:08:02

so what pathom sees is that you have already an id (wiht value 0), and the missing name sees a resolver that requires no input, so it pulls from that, makes sense?

wilkerlucio01:08:09

(it also works the same in Pathom 2)

caleb.macdonaldblack01:08:10

I removed the input to simplify but it’s the same behaviour with an input

caleb.macdonaldblack01:08:11

(pco/defresolver foobar [{:keys [id]}]
  {::pco/output [:id :name]}
  {:id 1 :name "foobar"})

((p.eql/boundary-interface
   (pci/register [foobar]))
 {:pathom/eql [:id :name] :pathom/entity {:id 0}})

=> {:id 0, :name "foobar"}

wilkerlucio01:08:09

same thing, in this case, :name is missing, so it uses the ID, given the output is fixed, it fills the missing parts

wilkerlucio01:08:20

but pathom wont ever override values already present

wilkerlucio01:08:50

so you had :id 0 from start, Pathom will never change the data, that's why you see what looks inconsistent, but in this case I think we can argue that the resolver is returning something inconsistent based on the id

caleb.macdonaldblack01:08:21

Yeah I agree the resolver is bad. If there was a bug with the resolver where the input isn’t used, it could be combined with irrelevant output and wouldn’t be obvious. This happened when I was writing a test

caleb.macdonaldblack01:08:33

It’s nothing major, I was more curious if anything

wilkerlucio01:08:49

sure, no problem, its good to clarify the intentions 👍

wilkerlucio01:08:08

but I hope the process makes sense, if Pathom did override data it would be madness 😛

caleb.macdonaldblack01:08:36

Actually that does make sense now

wilkerlucio01:08:03

there is one idea though, that I think would be useful as a developer tool, is some plugins to validate output

wilkerlucio01:08:26

so in a case like this, pathom could see a resolver trying to modify some already present data, anda this is a strong indication that something is flawed in the logic of the resolvers

wilkerlucio01:08:00

and notify the user in some way, or even break

caleb.macdonaldblack01:08:38

Ah yeah, that would’ve been a good indicator for me. I can’t imagine this happens often though.

wilkerlucio01:08:13

yeah, the idea is to be some kind of linter thing, another thing I would like to catch for example, is if the output contains more keys than expressed in ::pco/output, this is a strong indicator that the output definition is incomplete

cyppan05:08:39

We use that a lot (incomplete output declarations), only putting needed keys for pathom to resolve the graph (like joins), to me it’s actually a feature, at least for our usage. We do that because it allows our (quite rich and complex) data to evolve in an independent way without impacting every time the resolver layer.

cyppan05:08:45

But yeah an optional « lint » plugin looks like a good idea, for more strict use cases.

wilkerlucio16:08:43

yeah, the motivation for that is to avoid situations where an attribute works on a query, but not in another, for example, if a resolver declaration says it only outputs :a, but the code outputs :a and :b, a query for [:a :b] will get both values, but a query for [:b] will get nothing

wilkerlucio17:08:11

its a subtle issue that can get painful to find out

wilkerlucio17:08:42

but I'm realizing I have this in my head for a long time, and it isn't a problem on strict mode (that would reject the request for :b given it doesnt know about it)

wilkerlucio17:08:53

but that's still a thing for lenient mode

cyppan17:08:04

I understand, I’m personally fine with this behavior

wilkerlucio17:08:28

cool, and it will not change 🙂

👌 2
wilkerlucio01:08:35

not my priority to make this, but if anything would want to give it a try, the code could be later integrated as a built-in plugin

markaddleman18:08:24

I'm starting to use caching in Pathom3. The API is very easy to integrate, so thanks! One oddity: From what I understand, resolvers require caches to support protocol pcache/CacheStore but the plan cache does not. The plan cache assumes a cache atom from clojure.core.cache . Does it make sense for the plan cache to support the protocol? I think that would mildly simplify the API

wilkerlucio18:08:33

@markaddleman core.cached is a separate library, and it doesn't work on CLJS for example, so I dont plan to integrate directly with that (altough there are code examples on how to integrate with it)

wilkerlucio18:08:58

Pathom extends atoms and volatiles to implement pcache/CacheStore protocol, and that's whats used by default everywhere

markaddleman19:08:15

In the latest alpha, I think Pathom specs require that the plan cache be an atom. I supplied a pcache/CacheStore record to it and Pathom got very upset

markaddleman19:08:08

Pathom with guardrails enabled reports a lot of spec failures

wilkerlucio19:08:00

oh, right, the specs, yeah, I can see the spec is wrong, I can fix it later today, thanks for the report

wilkerlucio19:08:29

@markaddleman do you mind opening an issue just for tracking?

wilkerlucio21:08:07

update landed on master, can you test if works as expected in your case now?

markaddleman18:08:22

Finally got a chance to test the commit. Looks good

wilkerlucio19:08:57

thanks, I'll cut a new release with that later today