This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-11
Channels
- # adventofcode (8)
- # announcements (1)
- # arachne (23)
- # beginners (146)
- # boot (4)
- # calva (2)
- # cider (48)
- # cljs-dev (17)
- # clojure (214)
- # clojure-austin (2)
- # clojure-berlin (1)
- # clojure-europe (9)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-sanfrancisco (2)
- # clojure-spec (124)
- # clojure-uk (67)
- # clojured (3)
- # clojurescript (95)
- # community-development (7)
- # cursive (68)
- # data-science (1)
- # datomic (80)
- # emacs (19)
- # figwheel (3)
- # figwheel-main (5)
- # fulcro (61)
- # javascript (2)
- # kaocha (1)
- # off-topic (25)
- # pathom (21)
- # pedestal (1)
- # perun (4)
- # reitit (11)
- # ring-swagger (2)
- # shadow-cljs (55)
- # spacemacs (4)
- # sql (8)
- # test-check (16)
- # tools-deps (2)
- # vim (13)
- # yada (4)
@wilkerlucio How does one use parameters when querying with an ident aka with a single input?
There aren't any parameters in (:ast env)
like usual.
@mroerni can you please share the query you are trying to run?
edn
[({[:preference-list/by-slug "was-sollen-wir-mit-20-000eur-anfangen"]
[:dbas.issue/slug {:preferences [{:position [:id :text :cost]}]}]}
{:token "****"})]
Where my api looks like this:
clojure
(pc/defresolver preferences [{{{:keys [token]} :params} :ast} {slug :preference-list/by-slug}]
{::pc/input #{:preference-list/by-slug}
::pc/output [:dbas.issue/slug {:preferences [:position [:id :text :cost]]}]}
....)
that output seems wrong, this part [:position [:id :text :cost]]
that edn looks ok, altough there is another syntax that makes the params easier to find, like:
[{([:preference-list/by-slug "was-sollen-wir-mit-20-000eur-anfangen"] {:token "****"})
[:dbas.issue/slug {:preferences [{:position [:id :text :cost]}]}]}]
The query is made by fulcro with: (df/load this [:preference-list/by-slug slug] PreferenceList {:params {:token (:dbas.client/token connection)}})
ah, that's fine, in the end they are equivalent
but you can't get that params in this level, because what's been processed is the :dbas.issue/slug
what you could do is have a plugin or a custom ident reader to process this param and make it part of the env
example plugin:
(def token-param-plugin
{::p/wrap-read
(fn [reader]
(fn [env]
(let [token (get-in env [:ast :params :])]
(reader (cond-> env token (assoc : token))))))})
this way no matter in what level the token is provided, anywhere deeper you will have the token
That would actually be great. The token gets resolved to a user-id anyway in a bunch of mutations and resolvers.
another suggestion, I'm seeing you using some simple keywords, that can go back quickly in pathom since all attributes live in a shared world
I suggest you use namespaced keywords everywhere
I will do that. Thank you very much. The plugin is exactly the right solution for me.
@wilkerlucio One more thing.
If I want this param in my mutations as well, do I just have to use ::p/wrap-parser
instead of ::p/wrap-read
?
@mroerni you can use ::p/wrap-parser
but that is a bit different since you get a full context and only once, you may want to look for ::p/wrap-mutate
instead
but check some examples on how to use that (from pathom source) because mutations are a bit different because they return a map with an action, and what you want to wrap is the action
How would I cancel the read, if the token is not present / invalid? Like a HTTP401.
throw an exception