Fork me on GitHub
#pathom
<
2020-05-07
>
sergey.shvets04:05:00

@wilkerlucio Is there a special parser/reader required so ::pc/transform (pc/transform-auto-batch 10) works? I'm running on cljs and have async-parser, but all the requests are running consequently: https://take.ms/kNLoL

wilkerlucio05:05:51

is this a recursive query? the batch only works for sibling entities, when driling down it currently just chains the process

sergey.shvets05:05:33

[{([:hand-and-foot.games/id "TKSbTbE6O5Q0U89JhuHc"] {:with "params"})
  [:hand-and-foot.games/name
   :hand-and-foot.games/players
   :hand-and-foot.games/status 
   {:hand-and-foot.games/rounds 
    [:hand-and-foot.game-rounds/id
     :hand-and-foot.game-rounds/number
     
     {:hand-and-foot.rounds/moves 
      [:hand-and-foot.moves/number 
       :hand-and-foot.moves/player]}]}]}]

sergey.shvets05:05:57

These are sibling entities and they are independent

sergey.shvets05:05:08

Am I right that you can only have one ident per query?

sergey.shvets05:05:33

If you have multiple inputs then you need to use :pathom/context ?

sergey.shvets06:05:11

Aha, I just now realized that I can pass params to the (parser) through env. That makes my life muuuuch easier and queries are more readable now 🙂

uwo15:05:59

Just out of curiosity, is there a small library anywhere for turning datomic pull expressions into ASTs -- if not, is there a library that deals only with transforming EQL to an AST ( though I realize datomic pull isn't a proper subset of EQL).

uwo20:05:07

y'all rock. thanks

Brian19:05:05

How can I pass in a vector of things into a resolver? For instance, I have a bunch of item id's. I would like to send 2+ ids into my resolver and have it determine the similarity between those ids (meaning I can't send in 1 idea at a time). Hopefully this example shows what I am trying to do:

(defresolver similar-traits [env {:keys [[item/id]]}]
  {::pc/input  #{[:item/id]}
   ::pc/output [:result]}
  {:result (get-result <ids somehow>)})

sergey.shvets19:05:39

The second parameter in ident can be anything. So you can have ::pc/input #{:item/ids} and then use ident like [[:item/ids [:id1 :id2]]]

Brian19:05:15

Can you please write out the whole resolver @bear-z? I can't seem to get it working. I'd like the resolver to know that it's a vector of :item/ids not just an object with an :item/ids key

sergey.shvets20:05:36

I don't think you can do that unless it is a batch resolver. https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/connect/resolvers.html#_n1_queries_and_batch_resolvers. Try this:

(defresolver similar-traits [env input]
  {::pc/input  #{:item/id}
   ::pc/output [:result]
   ::pc/batch? true}
  {:result (get-result <your input will have a sequence of :item/id>)})
But batch resolvers will only be called when you have a sibling query (meaning they appear in joins), I don't think you can run them from the root.

sergey.shvets20:05:14

For the root, you can just create this extra key that will expect to receive a vector of :item/id

Brian20:05:21

@bear-z okay I think I understand now. One thing the docs don't provide is an example of how to actually pass that data into the parser. Do you know how to do that? I tried something like

(<!! ((du/get-parser) {} [{[{:item/id 1}
                            {:item/id 2}
                            {:item/id 3}]
                           [:result]}]))
but this yielded an error

sergey.shvets20:05:15

That won't work because your query is invalid. Ident always a tuple of 2 elements. Is there a reason that you want resolver to get :item/id separately and not as a list? Because I think you're overcomplicating it. If it always takes a list and returns some computed result, why would you add an overhead of batching and stuff?

Brian20:05:19

I don't know that batching is the answer I've only just learned about it. I just want to be able to send a vector of n {:item/id <id>}s into the parser and have a result computed. And I'm stuck on the n part. I have [{:item/id 1}{:item/id 2} ... {:item/id n}] . I can do something like

(defresolver ixn-similar-traits [env [:keys [item/ids]]]
  {::pc/input  #{:item/ids}
   ::pc/output [:result]}
  {:result (get-result ids)})
and then
(<!! ((du/get-parser) {} [{[:item/ids
                              [{:item/id 1}
                               {:item/id 2}
                               {:item/id 3}]]
                             [:result]}]))
but the resolver won't be able to check to ensure that :item/ids is actually a vector of maps with :item/id keys. I would like to further describe to the resolver that it should only work when receiving a vector of maps with :item/id keys. Expressed in edn [{:item/ids [:item/id]}]

sergey.shvets21:05:55

You can add a spec inside resolver or even a simple assert

sergey.shvets21:05:35

something like that:

(s/def ::item-map (s/keys :req [:item/id]))
(s/def ::items-coll (s/coll-of ::item-map))
And then inside your resolver simple: (s/valid? ::items-coll input) Full guide is here: https://clojure.org/guides/spec#_collections