pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
markaddleman 2021-02-19T00:27:08.311600Z

Thanks. I may have oversimplified the real use case. In real life, dimensions-attributes pulls data from a elastic search which may have zero, one or many documents that match a query

markaddleman 2021-02-19T00:27:55.311900Z

I feel like there ought to be a solution on the field-list resolver by using pco/? but I can't find a magic combination to get the results that I want

πŸ‘€ 1
wilkerlucio 2021-02-19T00:35:54.312500Z

@markaddleman just did tried here

wilkerlucio 2021-02-19T00:36:01.312700Z

I believe this has the change you want:

(pco/defresolver field-list [input]
  {::pco/input  [{:attributes/dimensions [(pco/? :attribute/id)]}]
   ::pco/output [{:pivot-table/fields [:pivot-table.fields/list
                                       :pivot-table.fields/count]}]}
  {:pivot-table/fields {:pivot-table.fields/count (count (:attributes/dimensions input))
                        :pivot-table.fields/list  (mapv (comp (fn [raw] {:pivot-table.field/id raw}) :attribute/id) (:attributes/dimensions input))}})

wilkerlucio 2021-02-19T00:36:13.312900Z

try with this resolver modified, and let me know if that's expected result now

markaddleman 2021-02-19T00:36:31.313100Z

Thx. I'll give it a try right now

wilkerlucio 2021-02-19T00:37:16.313300Z

ops. I just noticed this broken the first example ("not empty")

markaddleman 2021-02-19T00:37:51.313500Z

Yeah

markaddleman 2021-02-19T00:38:00.313700Z

I thought I had tried that πŸ™‚

markaddleman 2021-02-19T00:38:16.313900Z

It's as if pco/? is causing Pathom to give up too early

dehli 2021-02-19T00:38:59.314100Z

Is it expected that we’d need to make it optional? I would think that {:attributes/dimensions []} would still fulfill:

[{:attributes/dimensions [:attribute/id]}]

wilkerlucio 2021-02-19T00:39:10.314300Z

its different specifications

wilkerlucio 2021-02-19T00:39:26.314500Z

I guess in his case, the list is mandatory, but the some parts of the list content are optional

wilkerlucio 2021-02-19T00:40:17.314700Z

Pathom will only consider a sub-query valid if the required fields there are fulfilled

wilkerlucio 2021-02-19T00:40:28.314900Z

in that sense, the Pathom behavior is correct in the initial example

wilkerlucio 2021-02-19T00:40:33.315100Z

because the "empty" case can't fulfill the item detail

wilkerlucio 2021-02-19T00:41:03.315400Z

altough, this seems a special case up to discussion, over what to do when the collection is empty

wilkerlucio 2021-02-19T00:41:11.315600Z

in this case, should the input be considered valid, or invalid?

wilkerlucio 2021-02-19T00:42:05.315800Z

@markaddleman changing from required to optional and stop working is for sure a bug, going to work on that in a bit

markaddleman 2021-02-19T00:42:42.316Z

Thanks! This is one of the last bits for me to switch completely to Pathom3.

markaddleman 2021-02-19T00:43:04.316200Z

(to be clear, this is new functionality - I haven't tried this in Pathom2)

wilkerlucio 2021-02-19T00:43:25.316400Z

no nested inputs in Pathom 2, you are living the edge here πŸ™‚

markaddleman 2021-02-19T00:43:38.316600Z

lol

dehli 2021-02-19T00:43:53.316800Z

I have many comments in our pathom2 code about where we will benefit from nested inputs πŸ™‚

wilkerlucio 2021-02-19T00:44:36.317Z

nice, and Im really asking your opinion here

wilkerlucio 2021-02-19T00:44:47.317200Z

in case of empty collections, what you think would be the most sane default?

wilkerlucio 2021-02-19T00:44:52.317400Z

consider the input valid, or invalid?

wilkerlucio 2021-02-19T00:45:11.317600Z

(currently is invalid)

wilkerlucio 2021-02-19T00:46:22.317800Z

and to make a case for valid, the @markaddleman code would work without need for optionality on the fields, if valid was the answer

dehli 2021-02-19T00:47:09.318Z

In my opinion an empty collection is valid b/c it does fulfill the contract. For every item in the collection (zero items) they have an :attribute/id

wilkerlucio 2021-02-19T00:47:20.318300Z

yeah, I'm tending to that side too

wilkerlucio 2021-02-19T00:47:40.318500Z

most nested inputs are mostly about aggregation, and aggregation on empty collections most commonly expected to be valid

markaddleman 2021-02-19T00:47:57.318800Z

From my standpoint, it took a little bit of staring to understand why the empty collection was not triggering the id resolver.

markaddleman 2021-02-19T00:48:02.319Z

It would have been more natural if it had

wilkerlucio 2021-02-19T00:48:16.319200Z

yeah, ok, expect that to change, soon πŸ™‚

πŸ™ 2
dehli 2021-02-19T00:51:08.319600Z

awesome! what happens if some of the elements fulfill the nested input requirement but others don’t? I don’t have a real life example, but just curious

wilkerlucio 2021-02-19T00:55:19.319800Z

in that case its considered a match, but some items may have missing requirements

wilkerlucio 2021-02-19T00:55:41.320Z

wonder if would be sane to filter it out

markaddleman 2021-02-19T00:58:33.320200Z

From my standpoint, it would be sane to filter those out. I conceptualize pathom's behavior as a database JOIN operation. If some attributes don't exist on one side of the join, they aren't in the result set

☝️ 1
dehli 2021-02-19T01:05:11.320500Z

ya, i also think filtering out those missing the required key is sane behavior. if you didn’t want them filtered out i’d imagine you could make the nested key an optional key instead of required

wilkerlucio 2021-02-19T01:16:51.320800Z

I agree with you guys

wilkerlucio 2021-02-19T01:17:15.321Z

valid empty inputs just landed on master! @markaddleman you may wanna give a try if you still up πŸ™‚

πŸš€ 2
markaddleman 2021-02-19T01:17:39.321300Z

right after dinner. Thanks!

markaddleman 2021-02-19T01:56:37.322300Z

Works perfectly!

markaddleman 2021-02-19T01:56:40.322500Z

Thank you!

wilkerlucio 2021-02-19T02:07:21.322700Z

you'r welcome πŸ™‚

wilkerlucio 2021-02-19T02:08:07.323200Z

so now in cases of collections and parts of the items are missing the requirement, these items are filtered out

markaddleman 2021-02-19T02:08:44.323400Z

Yep. I just updated my code to remove pco/? . Makes it easier to understand, I think

wilkerlucio 2021-02-19T02:08:58.323600Z

yeah, and is the correct expression in your case

dehli 2021-02-19T03:58:46.323900Z

that’s awesome! thanks for the quick updates! excited to play around with the changes

wilkerlucio 2021-02-19T12:59:32.324700Z

πŸŽ‰ New docs for how nested input filtering behaves: https://pathom3.wsscode.com/docs/resolvers#nested-inputs-filtering

πŸ‘ 6
wilkerlucio 2021-02-19T13:01:29.325400Z

πŸŽ‰ New built-in plugin, now you can easely make mutation params resolve like resolver inputs! https://pathom3.wsscode.com/docs/built-in-plugins/#resolve-mutations-params

6
πŸŽ‰ 1
wilkerlucio 2021-02-19T13:01:50.325600Z

@cjmurphy if I remember right you were looking for this one a long time ago

1
fjolne 2021-02-19T16:49:34.330600Z

nice! would be great to be able to apply this plugin non-globally to a single mutation in opts map, kinda like augmentation via pco/transform

2021-02-19T16:56:59.331400Z

@wilkerlucio Looks like submitting invalid queries can cause the UI to lock up on Pathom Viz

2021-02-19T16:57:24.331800Z

i.e. [{[:curriculum/uuid <snip>]}]

2021-02-19T16:57:50.332400Z

Which is missing the value to the map which should def. error

2021-02-19T16:57:58.332800Z

but the UI shouldn’t require a hard reload IMO

wilkerlucio 2021-02-19T16:59:26.333700Z

not this plugin directly, but you can make a transform for that

πŸ‘ 1
wilkerlucio 2021-02-19T17:00:14.334300Z

agreed, can you please open an issue at the pathom viz repo?

2021-02-19T17:09:58.335100Z

https://github.com/wilkerlucio/pathom-viz/issues/25

πŸ‘ 1
2021-02-19T17:10:09.335400Z

Side note, thanks for the amazing tool!

πŸ™ 1
dehli 2021-02-19T19:29:52.338Z

Can you specify params for specific inputs in your resolver? I’d like to have a resolver depend on an input with a specific parameter always applied. My current workaround is to create another resolver that always applies the param but was curious if I could do it along with the input.

wilkerlucio 2021-02-19T19:48:42.340100Z

no support for that

dehli 2021-02-19T19:51:18.340300Z

πŸ‘ thanks! i think i can accomplish what i’m trying to do when i switch to pathom3 by using nested inputs along with the filtering of missing keys

markaddleman 2021-02-19T20:48:13.340600Z

Related to yesterday's discussion - Now my field-list resolver takes two separate inputs. Both of which can be optional. The first query returns the result I expect. The second query should only invoke the dimension-attributes, dimension->attr-id resolvers and field-list resolvers but returns an empty result instead.

dehli 2021-02-19T21:25:44.341100Z

I think this is b/c with your second option you only provide :k1 so it seems like it’s impossible to get to :attributes/profiles which is not marked as optional in your field-list resolver

dehli 2021-02-19T21:27:00.341300Z

The sub-key is optional but it still needs a key of :attributes/profiles which pathom cannot get to with your second query since the only resolver that provides :attributes/profiles requires both :k1 and :k2 .

dehli 2021-02-19T21:28:59.341700Z

I bet if you updated the field-list input to be this it would work: (pco/? {:attributes/profiles [(pco/? :attribute/id)]})

dehli 2021-02-19T21:30:35.342Z

or another option would be to mark :k2 as optional in your profile-attributes resolver

wilkerlucio 2021-02-19T21:40:31.342200Z

@markaddleman before I check it closer, did you upgraded Pathom today? because today I made a fix related to nested optional inputs

wilkerlucio 2021-02-19T21:41:43.342400Z

one other tip, you can use the arity 3 on process to make your execution result simpler (by removing the nesting under the placeholder):

(p.eql/process env
  {:k1 "not empty"}
  [{:pivot-table/fields
    [:pivot-table.fields/count
     :pivot-table.fields/list]}])

markaddleman 2021-02-19T21:42:15.342600Z

Yes, I'm using head

markaddleman 2021-02-19T21:43:19.342800Z

doh - Thanks for the arity 3 pointer. That simplifies things.

markaddleman 2021-02-19T21:46:49.343100Z

@dehli

(pco/? {:attributes/profiles [:attribute/id]})
does not pass a guardrails check. I've been meaning to ask if it should

wilkerlucio 2021-02-19T21:47:47.343300Z

@markaddleman wrong place, this is how you do it:

{(pco/? :attributes/profiles) [:attribute/id]}

πŸ‘ 2
wilkerlucio 2021-02-19T21:47:58.343600Z

I just tested, that got some results with your code

wilkerlucio 2021-02-19T21:48:05.343800Z

and the things that @dehli said were accurate

wilkerlucio 2021-02-19T21:48:14.344Z

its the k2 missing dep that's making pathom give up on that

wilkerlucio 2021-02-19T21:49:02.344200Z

Im quite happy how you are pushing the boundaries, will be even happier if all works as expected XD

1
markaddleman 2021-02-19T21:49:32.344600Z

No worries. I sort of expected this when I decided to go P3.

markaddleman 2021-02-19T21:49:56.344800Z

And, to be sure, P3 is proving to be a win for me overall

markaddleman 2021-02-19T21:52:48.345Z

Yeah, if I mark :k2 as optional in the profile->attri-id resolver, field-list produces results but it's the wrong results. There should not be profile in the result from field-list because :k2 isn't in the input

wilkerlucio 2021-02-19T21:53:29.345200Z

I'm gonna check that, in the meantime, what about optional on :attribute/profiles?

markaddleman 2021-02-19T21:54:39.345400Z

That works but... (i think I tried earlier and had a problem)

wilkerlucio 2021-02-19T21:55:06.345600Z

about the optional :k2, I believe its behaving correctly, you made that optional, so it runs the resolver and retuns the list

πŸ‘ 1
markaddleman 2021-02-19T21:57:24.345900Z

This yields the correct result:

::pco/input  [{:attributes/dimensions [:attribute/id]}
               {(pco/? :attributes/profiles) [:attribute/id]}]

markaddleman 2021-02-19T21:57:56.346100Z

However, this

::pco/input  [{(pco/? :attributes/dimensions) [:attribute/id]}
               {(pco/? :attributes/profiles) [:attribute/id]}]
produces a guardrails exception

markaddleman 2021-02-19T21:58:10.346300Z

And this ^^ is closer to my real use case

wilkerlucio 2021-02-19T21:58:21.346500Z

interesting, I have a guess on why πŸ‘€

wilkerlucio 2021-02-19T21:59:41.346700Z

ok, that seems a simple spec oversight, the result is correct?

wilkerlucio 2021-02-19T22:00:20.346900Z

spec fixed on master

πŸŽ‰ 1
markaddleman 2021-02-19T22:04:15.347200Z

I haven't tried turning off guardrails. I'll update to newest master and retest in a few minutes

markaddleman 2021-02-19T22:06:49.347400Z

Under latest master,

::pco/input  [{(pco/? :attributes/dimensions) [:attribute/id]}
               {(pco/? :attributes/profiles) [:attribute/id]}]
produces correct results

wilkerlucio 2021-02-19T22:09:47.347600Z

I usually use guardrails with throw false

wilkerlucio 2021-02-19T22:09:53.347800Z

so even when it complains, things still go on

πŸ‘ 1