Fork me on GitHub
#pathom
<
2022-01-26
>
shvetsm18:01:50

@wilkerlucio Hey thank you so much for building this great framework. I have a couple questions 1. Say I have records with

[ {:value "A" :record.created-by-id "123" :record.last-modified-by-id "456" }
  {:value "B" :record.created-by-id "789" :record.last-modified-by-id "456" }]
and then I have a service that does a batch lookup for users. What is the recommended way of setting this lookup up if I would like to return something that assigns a name to both created-by and last-modified-by I am sure this is a common problem šŸ™‚. We have a lot of leeway with the shape of the returned data, though we do need a batch lookup. One will be ideal, we can def live with two (one for created one for last-modified). We do need to be able to tell which one is which. 2. We are starting development now. How alpha is Pathom3? I saw someone asking about parallel parser and such. We are not shy about using alpha (got a lot of mitosin floating on the project), but would thought I would ask. Once again thanks for all your hard work.

wilkerlucio18:01:20

hello šŸ™‚ 1. not what you want to do, what you mean by assign a name to created-by and last-modified-by? how these data is related to the records you presented? 2. Pathom 3 has a mostly stable API already, not expecting that to have big changes, that said, the basic features (local processing and serial process) seem to be stable, I've been using in a couple of projects and there are other users here too. I would say that features like distributed graphs is the one to not have a lot of confidence at this point, not very used and likely to be bugged at this stage

shvetsm18:01:59

ok to be specific: I am modelling a resolver that gives me

[{:record/id "42" :record/created-by-id "user-id-1" :record/last-modified-by-id "user-id-2" ]
and so on I also have an api that can look up usernames in bulk so I can pass in
["user-id-1" "user-id-2"}]
and get back
[{:user/id "user-id-1 :user/display-name "Billy Bob"}
 {:user/id "user-id-2 :user/display-name "Jane Smith"}]

shvetsm18:01:12

So what I am trying to do here is return something like

{:records [ {:record/id  "42" 
             :record/created-by-name "Billy Bob"
             :record/last-modified-by "Jane Smith"}]

shvetsm18:01:53

once again it does not need to be this shape, just as long as I can navigate to the name

shvetsm18:01:14

for each created-by and last-modifed-by

shvetsm18:01:44

these values appear on 90% of our data, which needs to be displayed with the name on the UI

wilkerlucio18:01:48

cool, the trick is to change your bulk input, and label the data you already have, so instead of ["user-id-1" "user-id-2"], it would be more like: [{:user/id "user-id-1"} {:user/id "user-id-2"}]

shvetsm18:01:57

I have that

shvetsm18:01:28

I have the batch resolver working

wilkerlucio18:01:04

that sounds correct to me, whats the part I can help you with?

shvetsm18:01:13

I did an alias between :record/created-by-id and :user/id

shvetsm18:01:31

but I have 2 "user/ids" on each of this record

shvetsm18:01:45

one for created by and one for last modified by

shvetsm18:01:11

, how do I get both names to return for each record

shvetsm18:01:57

I set up 2 aliases to map from created-by-id and last-modified-by-id for user/id

shvetsm18:01:17

but when I write my query I can only get 1 of the mappings

shvetsm18:01:43

here is my actual query

[{:notes [:note/id :note/created-by-id 
          :user/display-name]}]
 

shvetsm18:01:49

there are two issues here. I don't know which one the user/display-name is (created by or last modified by)

shvetsm18:01:04

and only 1 is selected

shvetsm18:01:50

I tried to model it with a join [{:note/created-by-id [:user/id]}]

shvetsm18:01:57

but that does not work in batch

shvetsm18:01:16

because the query results are nested now

shvetsm18:01:46

I am asking because I think that this is an easy problem and I am just a noob šŸ™‚

shvetsm18:01:34

(pc/defresolver note-test-resolver [_ _]
  {::pc/output [{:notes [:user/id]}]}
  {:notes [{:note/id               "123"
            :note/created-by-id    "0495e640-b11c-4b58-a29d-8ce0ba485144"
            :note/last-modified-by "04bfa00e-d161-46b4-b2cf-d829905c86db"}
           {:note/id               "789"
            :note/created-by-id    "047ab33e-fef2-4c3d-9d36-f8d3b0170525"
            :note/last-modified-by "047893f7-e697-436f-8259-2b6e0ae45c1d"}
           {:note/id               "456"
            :note/created-by-id    "170aa5c2-bcab-4cc3-990e-2e67f996fc58"
            :note/last-modified-by "d85c0a12-22ff-40a2-a050-811606ee375e"}]})

shvetsm18:01:26

(pc/defresolver user-resolver [_ -inputs]
  {::pc/input     #{:user/id}
   ::pc/output    [:user/display-name]
   ::pc/transform pc/transform-batch-resolver}
  (let [inputs (if (sequential? -inputs) -inputs [-inputs])
        users  (get users from db)
        items  (map (fn [user] {:user/id           (:id user)
                                :user/display-name (:display-name user)
                                :user/email        (:email user)}) users)]
    (pc/batch-restore-sort {::pc/inputs     inputs
                            ::pc/key        :user/id
                            ::batch-default (fn [] {:user/display-name "NO-NAME"})} items)))

shvetsm18:01:01

(def registry
  [ note-test-resolver user-resolver
   (pc/alias-resolver :note/created-by-id :user/id)
   (pc/alias-resolver :note/last-modified-by-id :user/id)
   pc/index-explorer-resolver])

shvetsm18:01:13

this is how I set it up

shvetsm18:01:46

if it were just created-by I needed to lookup there would be 0 questions

wilkerlucio21:01:50

no worries, taking a look at your text now

wilkerlucio21:01:51

if you have multiple options for one attribute, there will be ambiguity (which is nice to avoid when you can), having a nested key for each (one for created, one for last modified) can be a way to solve the ambiguity

wilkerlucio21:01:35

so in this case, you can have two extra resolvers, as:

(pco/defresolver nav-user-created [{:keys [note/created-by-id]}]
  {::pco/output
   [{:note/created-by [:note/user-id]}]}
  {:note/created-by {:user/id created-by-id}})

(pco/defresolver nav-user-last-update [{:keys [note/last-modified-by-id]}]
  {::pco/output
   [{:note/last-modified-by [:note/user-id]}]}
  {:note/last-modified-by {:user/id last-modified-by-id}})

wilkerlucio21:01:04

then you can query:

[{:notes [:note/id {:note/created-by [:user/name]}]
`

wilkerlucio21:01:23

please let me know how it goes

dehli19:01:31

If I have an attribute marked as optional in my request, is it expected that Iā€™d get the Insufficient data calling resolver error message when trying to reach that attribute?

markaddleman19:01:15

Do you have two resolvers that output the same attribute?

markaddleman19:01:56

I think this is a planning bug. I've been meaning to create a repro case for it

dehli20:01:07

great! ill try to create one as well. ill message here w/ the ticket when i do

šŸ™ 1
markaddleman20:01:20

I think I got around it by avoiding optional entirely. I have one resolver that requires the attribute and one that does not. Then, I use priority to get the behavior that I want

šŸ‘ 1
wilkerlucio21:01:52

the only way you may get that still is if some other required attribute depends on that, in this case it still invalid, otherwise please open an issue with a repro šŸ™‚