Fork me on GitHub
#pathom
<
2019-02-11
>
Björn Ebbinghaus00:02:45

@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.

wilkerlucio00:02:49

@mroerni can you please share the query you are trying to run?

Björn Ebbinghaus00:02:52

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]]}]}
 ....)

wilkerlucio00:02:32

that output seems wrong, this part [:position [:id :text :cost]]

wilkerlucio00:02:18

that edn looks ok, altough there is another syntax that makes the params easier to find, like:

wilkerlucio00:02:36

[{([:preference-list/by-slug "was-sollen-wir-mit-20-000eur-anfangen"] {:token "****"})
  [:dbas.issue/slug {:preferences [{:position [:id :text :cost]}]}]}]

Björn Ebbinghaus00:02:00

The query is made by fulcro with: (df/load this [:preference-list/by-slug slug] PreferenceList {:params {:token (:dbas.client/token connection)}})

wilkerlucio00:02:13

ah, that's fine, in the end they are equivalent

wilkerlucio00:02:40

but you can't get that params in this level, because what's been processed is the :dbas.issue/slug

wilkerlucio00:02:23

what you could do is have a plugin or a custom ident reader to process this param and make it part of the env

wilkerlucio00:02:23

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))))))})

wilkerlucio00:02:40

this way no matter in what level the token is provided, anywhere deeper you will have the token

Björn Ebbinghaus00:02:47

That would actually be great. The token gets resolved to a user-id anyway in a bunch of mutations and resolvers.

wilkerlucio00:02:14

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

wilkerlucio00:02:23

I suggest you use namespaced keywords everywhere

Björn Ebbinghaus00:02:31

I will do that. Thank you very much. The plugin is exactly the right solution for me.

👍 5
Björn Ebbinghaus13:02:57

@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?

wilkerlucio13:02:18

@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

wilkerlucio13:02:52

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

Björn Ebbinghaus13:02:58

How would I cancel the read, if the token is not present / invalid? Like a HTTP401.

wilkerlucio13:02:03

throw an exception