Fork me on GitHub
#pathom
<
2019-12-09
>
mitchelkuijpers15:12:20

Is it possible with pathom to add something like: :roles-needed [:admin] to the defresolver map?

mitchelkuijpers15:12:28

And then use that in a plugin to check roles?

mitchelkuijpers15:12:59

I have it working a bit by checking: (::pc/resolver-data env) that would then include :roles-needed

mitchelkuijpers15:12:22

I have something like [{:foo [:secret]}] if have a resolved for this I can find :roles needed when querying for this. But when I just query for :foo it will simply return the value without me knowing that there are roles needed

Björn Ebbinghaus15:12:25

@mitchelkuijpers Yes. It is. I have something similar, where you can get inspiration. I wrote a plugin so that I can give my mutations a spec for their parameters.

clojure
(def spec-plugin
  {::p/wrap-mutate
   (fn [mutate]
     (fn [env sym params]
       (if-let [spec (get-in env [::pc/indexes ::pc/index-mutations sym ::s/params])]
         (if (s/valid? spec params)
           (mutate env sym params)
           (do
             (log/warn (s/explain spec params))
             (throw (ex-info "Failed validation!" (s/explain-data spec params)))))
         (mutate env sym params))))})

(defmutation set-vote [{:keys [connection AUTH/account-id] :as env} {proposal-id :proposal/id
                                                                     account     :account/id :as params}]
  {::pc/params [:proposal/id :account/id :account/id]
   ::pc/output [:proposal/id]
   ::s/params  ::upsert-vote}
 ....)

Björn Ebbinghaus16:12:53

@wilkerlucio While I am at it. Is there a better way to get the current mutation/resolver map in a plugin other than (get-in env [::pc/indexes ::pc/index-mutations sym ::s/params]) ?

mitchelkuijpers18:12:36

Ah that helps a lot thank you @mroerni

wilkerlucio19:12:40

@mroerni that's the intended way, I plan to keep those keys stable, so it shoulnd't break, but I can add a few helpers to facilitate the access, something like (pc/mutation-data env 'my-mutation), what you think?

mitchelkuijpers20:12:21

@wilkerlucio for reads do I first need to get the sym from [::pc/indexes ::pc/index-attributes] and then to :attr-output-in and then get the symbol from [::pc/indexes ::pc/indexes-resolvers] ?

mitchelkuijpers20:12:41

(defn get-resolver [env]
  (let [k (get-in env [:ast :key])
        sym (get-in env [::pc/indexes ::pc/index-attributes k ::pc/attr-output-in])]
    (reduce
     (fn [m k]
       (merge m (get-in env [::pc/indexes ::pc/index-resolvers k])))
     {}
     sym)))
This seems to work, very nifty those maps with all the paths