Fork me on GitHub
#pathom
<
2020-06-10
>
tomjkidd18:06:30

Is there a preferred way to handle authorization concerns with resolvers?

wilkerlucio20:06:11

nope, its open for you to decide, a common pattern is provide some auth-token on the environment so the resolvers can use it

tomjkidd20:06:43

Alright, we have been using the environment to handle our concern, and had a false start by trying to incorporate some of the grant/role information as ::pc/input properties

tomjkidd20:06:11

And, thank you!

dvingo20:06:59

I was looking into a way to tag mutations/resolvers with auth needs, and came across the transform https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/connect/shared-resolvers.html#connect-transform helper. I think something like this shape would get there

(defn simple-tform
  [{::pc/keys [mutate resolve] :as env}]
  (log/info "ENV is: ") (pprint env)
  (if resolve
    (assoc env ::pc/resolve
               (fn [en params]
                 (log/info "IN simple tform resolve")
                 (resolve en params)))
    (assoc env ::pc/mutate
               (fn [en params]
                 (log/info "IN simple tform mutate")
                 (log/info "env is: ")
                 (pprint (keys en))
                 (mutate en params)))))

(pc/defresolver res1 [_ _]
  {::pc/output    [::test]
   ::pc/transform simple-tform
   ::my-ns/require-auth? true
   ::my-ns/auth-roles #{:admin}}
  (log/info "Hello")
  {::test "hello this is my name"})

tomjkidd21:06:32

I like the extension to defresolver to incorporate expected roles here

tomjkidd21:06:48

Thank you, will continue to learn about this