Fork me on GitHub
#graphql
<
2019-09-18
>
erwinrooijakkers08:09:27

So I should not use conj but inject instead?

erwinrooijakkers08:09:43

I prefer an interceptor to avoid the deep destructuring of the request in every method

erwinrooijakkers08:09:12

And only check the JWT signature once

erwinrooijakkers10:09:11

This works:

(defn interceptors [schema]
  (let [opts {}]
    (pedestal/inject (default-interceptors schema opts)
                     roles-interceptor
                     :before
                     ::pedestal/json-response)))

gklijs10:09:14

Thanks for posting the solution, might wanna implement something like it myself.

erwinrooijakkers14:09:11

Hmm it actually does not work properly, it is too late 🙂

erwinrooijakkers14:09:49

This one is probably better:

(defn- inject-roles-interceptor [interceptors]
  (log/info interceptors)
  (pedestal/inject interceptors
                   roles-interceptor
                   :after
                   ::pedestal/inject-app-context))

erwinrooijakkers14:09:50

Hmm also too late 😕

erwinrooijakkers14:09:23

Before or after what interceptor do I have to place my own if I want it to provide data (decoded JWT) from the request in the context?

erwinrooijakkers14:09:07

I would expect after inject-app-context to be the right place:

(defn inject-app-context-interceptor
  "Adds a :lacinia-app-context key to the request, used when executing the query.
  The provided app-context map is augmented with the request map, as key :request.
  It is not uncommon to replace this interceptor with one that constructs
  the application context dynamically; for example, to extract authentication information
  from the request and expose that as app-context keys."
  {:added "0.2.0"}
  [app-context]
  (interceptor
    {:name ::inject-app-context
     :enter (fn [context]
              (assoc-in context [:request :lacinia-app-context]
                        (assoc app-context :request (:request context))))}))

erwinrooijakkers14:09:04

I want to use the added context in a resolver

erwinrooijakkers14:09:09

(defn- use-roles-resolver
  [ds {:keys [columns]}]
  (fn [{:auth/keys [roles] :as context} data _]
    ;; use the roles added by my interceptor
 ))

(defn- resolver-map
  [ds]
  {:query/component-basic (use-roles-resolver ds)})