This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-06
Channels
- # announcements (3)
- # beginners (83)
- # calva (11)
- # cider (24)
- # cljdoc (2)
- # cljs-dev (1)
- # clojure (216)
- # clojure-berlin (1)
- # clojure-dev (18)
- # clojure-europe (8)
- # clojure-italy (5)
- # clojure-losangeles (2)
- # clojure-nl (4)
- # clojure-spec (34)
- # clojure-uk (75)
- # clojuredesign-podcast (12)
- # clojurescript (33)
- # clojutre (13)
- # community-development (1)
- # core-async (38)
- # cursive (19)
- # datomic (28)
- # duct (3)
- # emacs (1)
- # events (5)
- # figwheel-main (3)
- # fulcro (93)
- # kaocha (20)
- # lambdaisland (2)
- # off-topic (40)
- # pathom (17)
- # pedestal (8)
- # quil (1)
- # re-frame (14)
- # reitit (19)
- # shadow-cljs (34)
- # sql (8)
- # tools-deps (6)
- # vim (1)
- # xtdb (8)
- # yada (18)
I have this query sent to a resolver.
[{([:integration/id #uuid "81890273-ccee-43cb-88b6-54bce85438f7"]
{:metric
{:metric/id #uuid "26b0037a-8a81-414b-b64d-906a9e607320",
:metric/name "test"}})
[{:metric/provider-points [:points]}]}]
Inside the resolver I am printing (-> env :ast :params)
and it is nil
. Is this expected? Aren't you supposed to be able to pass parameters to resolvers?Simple example:
(pc/defresolver points-example
[env
_]
{::pc/input #{:foo/id}
::pc/output [:foo/thing]}
(let [params (p/params env)]
(prn params)
{:foo/thing 1}))
When calling my parser:
(parser '[{([:foo/id "abc"] {:sort :asc}) [:foo/thing]}])
{}
=> {[:foo/id "abc"] #:foo{:thing 1}}
The printed params map is simply {}
even though I passed in parameters.The query is definitely parsed as having parameters:
(edn-query-language.core/query->ast
'[{([:foo/id "abc"] {:sort :asc}) [:foo/thing]}])
=>
{:type :root,
:children [{:type :join,
:dispatch-key :foo/id,
:key [:foo/id "abc"],
:params {:sort :asc},
:meta {:line 2, :column 6},
:query [:foo/thing],
:children [{:type :prop, :dispatch-key :foo/thing, :key :foo/thing}]}]}
Maybe that's what this is? https://github.com/wilkerlucio/pathom/issues/93
Wrote this
(defn ident-reader
"Like ident-reader, but ident key doesn't have to be in the index, this will respond
to any ident join. Also supports extra context with :pathom/context param."
[env]
(if-let [key (p/ident-key env)]
(let [params (get-in env [:ast :params])
extra-context (:pathom/context params)
ent (merge {key (p/ident-value env)} extra-context)]
(p/join (atom ent) (update-in env [:eql/params key] merge params)))
::p/continue))
Seems to work by adding the params for a key into the env. Don't think it's very robust though.yeah, I think its ok for a specific solution, but I'm not confortable as a general one, would be interested to see how that behaves over time, not something I want on core, but fine for users to make things like this 👍
it does, the problem is just a misunderstanding on how the query works, params are part of the AST, so you can add params for each entry, and the params for the parent join is a different thing, so at AST level, the param is just on the join, not on the attribute, but when you are writing a resolver, the AST is about the attribute, not about the join
another way to handle this is using ::p/parent-query
, I guess you can get the parent param from there, but see, those are different AST points, so you have to take that in consideration
makes sense?
adding: if you add the params to the attribute, then they will show up in params, but params form the join are not on the field, because they are not the same thing
yeah, correct
there are some examples demoing the AST with params, can help to understand where things get placed: https://edn-query-language.org/eql/1.0.0/specification.html#_parameters
Can you use joins as ::pc/input
?
#{:workload/id
{:workload/biz-factors [:biz-factor/id
:biz-factor/name]}}
Where for my query I just pass in
(parser '[{[:workload/id #uuid "1cf55797-bb5c-49cc-8e71-39a6f59c69b9"]
[:workload/foo]}])
It appears you can't but maybe I'm doing something wrong?