Fork me on GitHub
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.


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

Björn Ebbinghaus00:02:52

[({[: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:
(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]}]}]}]

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


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
   (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

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.


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

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?


@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

Björn Ebbinghaus13:02:58

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


throw an exception