Fork me on GitHub

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


And then use that in a plugin to check roles?


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


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.

(def spec-plugin
   (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)
             (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]) ?


Ah that helps a lot thank you @mroerni


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


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


(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])]
     (fn [m k]
       (merge m (get-in env [::pc/indexes ::pc/index-resolvers k])))
This seems to work, very nifty those maps with all the paths