This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-07
Channels
- # announcements (11)
- # architecture (2)
- # babashka (84)
- # beginners (226)
- # calva (7)
- # chlorine-clover (4)
- # cider (29)
- # clara (17)
- # clj-kondo (23)
- # cljs-dev (58)
- # cljsrn (60)
- # clojure (172)
- # clojure-europe (24)
- # clojure-finland (2)
- # clojure-italy (6)
- # clojure-nl (8)
- # clojure-spec (4)
- # clojure-uk (22)
- # clojurescript (44)
- # conjure (39)
- # core-async (64)
- # cursive (76)
- # data-science (15)
- # duct (3)
- # emacs (2)
- # events (5)
- # fulcro (30)
- # helix (4)
- # jackdaw (5)
- # juxt (1)
- # kaocha (1)
- # leiningen (4)
- # off-topic (9)
- # pathom (22)
- # re-frame (9)
- # reagent (33)
- # reitit (3)
- # ring (10)
- # ring-swagger (2)
- # shadow-cljs (192)
- # spacemacs (27)
- # specter (2)
- # sql (59)
- # vim (2)
@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
is this a recursive query? the batch only works for sibling entities, when driling down it currently just chains the process
[{([: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]}]}]}]
These are sibling entities and they are independent
Am I right that you can only have one ident
per query?
If you have multiple inputs then you need to use :pathom/context
?
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 🙂
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).
okay, nvm. Found it for EQL https://github.com/edn-query-language/eql/blob/master/src/edn_query_language/core.cljc
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>)})
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]]]
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/id
s not just an object with an :item/ids
key
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.For the root, you can just create this extra key that will expect to receive a vector of :item/id
@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 errorThat 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?
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]}]
You can add a spec inside resolver or even a simple assert
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