This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-05
Channels
- # announcements (7)
- # babashka (20)
- # beginners (130)
- # bristol-clojurians (1)
- # cider (14)
- # clj-kondo (7)
- # cljdoc (14)
- # cljs-dev (15)
- # cljsrn (16)
- # clojars (11)
- # clojure (190)
- # clojure-dev (4)
- # clojure-europe (7)
- # clojure-italy (9)
- # clojure-nl (3)
- # clojure-romania (6)
- # clojure-uk (51)
- # clojurescript (44)
- # component (4)
- # conjure (28)
- # cursive (1)
- # data-science (4)
- # datascript (1)
- # datomic (30)
- # duct (4)
- # emacs (1)
- # figwheel (4)
- # fulcro (56)
- # graalvm (4)
- # helix (51)
- # jackdaw (2)
- # jobs-discuss (12)
- # joker (4)
- # lambdaisland (1)
- # local-first-clojure (1)
- # meander (73)
- # mid-cities-meetup (2)
- # nrepl (4)
- # off-topic (43)
- # pathom (56)
- # re-frame (37)
- # reagent (26)
- # shadow-cljs (161)
- # slack-help (9)
- # spacemacs (1)
- # tools-deps (18)
- # xtdb (18)
@wilkerlucio Thanks for your suggestions yesterday. Both worked like a charm.
Here is my pass-down params script for reference:
(def params-down-pathom-plugin
{::p/wrap-read (fn [reader]
(fn [env]
(if-let [params (get-in env [:ast :params])]
(reader (as->
(map (fn [child]
[(:dispatch-key child) params])
(get-in env [:ast :children])) $
(into {} $)
(update env :parent-params merge $)))
(reader env))))})
(defn parse-query-params
"Parses query and ast to see if there any params related to the current query. Returns map with params or empty map."
[env]
(let [dispatch-key (get-in env [:ast :dispatch-key])
params (get-in env [:parent-params dispatch-key] {})]
params))
[{([: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]} {:limit 2 :order-by :hand-and-foot.game-rounds/number})]}]
Inside a resolver you need to call parse-query-params
and it will figure out if there are any params that are related to this resolver. It rolls down params only one level to the immediate children of a node where params have been applied.
It shouldn't be too hard to roll it down all the way, but I think it will do more harm than good.
another option is roll it down via :env
instead of changing the AST, this way you can have "accumulated" (could go deep merging all the way down) and the current
I haven't changed ast, I just added a new parameter to env
oh, right, I misread it 馃憤
you welcome!
Unless you have same dispatch keys with different params in your query it will support multiple params in different places of a query.
Can query have multiple idents for one join? Or you need to always create some "join node" that will accept multiple values as ident param and set them to the env?
I had a thought that probably the requirement for Idents can be loosened a bit from "only 2 arguments" to even number of arguments and I feel like this will open more opportunities, without changing parser/ast too much
I proposed this before, but was rejected: https://github.com/edn-query-language/eql/pull/9
but with this syntax you can write quries like:
[{{:latitude 42
:longitude 42.3}
[:location/name]}]
In my mind this is still way cleaner than the pathom parser specific :pathom/context
hack
Thanks for sharing. I haven't seen those before, since I'm very new to pathom and eql in general. I was planning to implement something similar to what Wilker suggesting here https://github.com/wilkerlucio/pathom/issues/140 with expand-thing-compound
and that should cover my problem. But on the other hand, allowing longer vectors in idents doesn't seem like a huge change to me. Of course, there might be nuances that I don't grasp yet. Just wanted to share an idea. The workaround with expand-thing-compound
is very simple one and pretty much need one extra resolver per project.
Oh, I get what you're saying. We can't specify outputs for resolver without knowing what will be inside the ident param
so, the best way for now is to use this:
[{([:init-context/a 42] {:pathom/context {:init-context/b "foo"}}) [:want/this]}]
I like your suggestion,
[{{:init-context/a 42 :init-context/b "foo"} [:want/this]}]
but to minimize changes to spec I think it would be better to keep it as this
[{[:init-context/a 42 :init-context/b "foo"] [:want/this]}]
If I'm not missing something then you just need an extra reader and loosen the spec if it has a validation for exactly two to the even?
How did you write reader for map ident in Pathom? Have you changed eql specs or pathom doesn't check for validity of the query beforehand?
I dislike the a 2+ vector idea as this join context as I call it is an associative ideas which we already have a perfectly fine representation for
of course the idea of how to determine the dispatch key came up, which is just currently ffirst
, so it depends on the hashmap in-memory ordering guarantees, but this hasn鈥檛 bit me yet
Isn't dispatch key for ident the whole vector? (or map in your case)
Actually, disregard. I see that it isn't. It is :first
what is foreign parser?
Actually, it seems like pathom context doesn't work for my case or I'm doing it totally wrong.
I have a resolver that has input #{:parent/id child/id}
and trying to call it:
[{'([:child/id "a2coh2mnsIyd35CL8PVv"] {:pathom/context {:parent/id "TKSbTbE6O5Q0U89JhuHc"}}) [:child/data]}]
and it isn't finding the proper resolver
When I connect my app into pathom-viz
, autocomplete works but index explorer don't
How can I debug it?
public API URL:
public code: https://github.com/souenzzo/caderninho/blob/master/src/br/com/souenzzo/caderninho.clj#L24
Solution
it's something with transit/unknown tags
(sp/setval (sp/walker fn?) sp/NONE response)
I have a resolver that has input #{:parent/id :child/id}
and trying to call it:
[{'([:child/id "a2coh2mnsIyd35CL8PVv"] {:pathom/context {:parent/id "TKSbTbE6O5Q0U89JhuHc"}}) [:child/data]}]
Get not-found in response. Is this supposed to work? Because I can't see what am I doing wrong.
@bear-z this should work, can you also try adding '*
to your query? so you can see all data available
[{'([:child/id "a2coh2mnsIyd35CL8PVv"] {:pathom/context {:parent/id "TKSbTbE6O5Q0U89JhuHc"}}) [:child/data '*]}]
No luck: Here is my query: https://take.ms/05ecK And here is the resolver it supposed to call: https://take.ms/6IOp1
are you using the open-ident-reader
?
ident-reader
:
(p/async-parser
{::p/env {::p/reader [p/map-reader
pc/async-reader2
pc/ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}}
::p/mutate pc/mutate-async
::p/plugins [(pc/connect-plugin {::pc/register pathom-resolvers})
p/error-handler-plugin
p/trace-plugin
params-down-pathom-plugin]}))
open-ident-reader does solve it.
Thank you!