Fork me on GitHub
#pathom
<
2022-04-14
>
aratare11:04:16

Hi @wilkerlucio, I'm having some params-related problem and I'm not sure what is causing it. I have a resolver that is expecting some params sent up by fulcro, and when I checked (-> env :ast :params) it is nil despite the param was sent up normally. I'll put the code snippets in this thread for illustration.

aratare11:04:08

Parser:

(p/parser {::p/env     {::p/reader                 [p/map-reader pc/reader2 pc/ident-reader pc/index-reader]
                          ::p/process-error          process-error
                          ::pc/mutation-join-globals [:tempids]}
             ::p/mutate  pc/mutate
             ::p/plugins [(pc/connect-plugin {::pc/register resolvers})
                          p/error-handler-plugin
                          p/trace-plugin
                          ;; FIXME: Seems to be fired twice
                          (p/post-process-parser-plugin (fn [output]
                                                          (let [output (-> output p/elide-not-found p/raise-errors)]
                                                            (if-let [errors (::p/errors output)]
                                                              errors
                                                              output))))]})

aratare11:04:23

Resolver:

(defresolver bookmarks-resolver
  [{{user-id :user/id} :request :as env} {:tab/keys [id] :as input}]
  {::pc/input  #{:tab/id}
   ::pc/output [{:tab/bookmarks bookmark-output}]}
  ...)

aratare11:04:50

Request (as shown in fulcro inspect):

aratare11:04:56

[({[:tab/id #uuid "bc1599de-e58a-4d3b-b61b-b0e50b6a2749"]
   [{:tab/bookmarks
     [:bookmark/id
      :bookmark/title
      :bookmark/url
      :bookmark/favourite
      :bookmark/image
      :bookmark/tab-id
      {:bookmark/tags [:tag/id :tag/name :tag/colour]}]}]}
  {:tab/password "v"})]

aratare11:04:31

As you can see I'm sending up :tab/password but it doesn't exist in (-> env :ast :params)

aratare11:04:50

Is there any special setup I'd need to do to be able to retrieve params?

wilkerlucio17:04:10

the problem here is the param location, because Fulcro injects the params to the ident, not to the attributes, so Pathom has it in a different location than you are expecting. there two ways around it, the most common seems to be to have a plugin to propagate params down, or you have to set the params in the query itself (instead of using the`:params` option from Fulcro)

wilkerlucio17:04:55

I dont have it now, but if you ask on #fulcro somebody probably has that code already to give to you

nivekuil21:04:40

{::p.eql/wrap-process-ast    (fn [process]      (fn [env ast]        (-> (if (:query-params env)              env              (assoc env :query-params                     (reduce                      (fn [qps {:keys [type params] :as x}]                        (cond-> qps                          (and (not= :call type) (seq params)) (merge params)))                      {}                      (:children ast))))            (process ast))))}

nivekuil21:04:06

oh, mine is the RAD one ported to pathom3

aratare00:04:45

@wilkerlucio Yep indeed a plugin is needed for this. Thank you and @U797MAJ8M for the help. It's working wonderfully now 🙂