graphql

2019-09-18T06:32:10.008Z

Iff you still want to add another interceptor, you can also use https://walmartlabs.github.io/apidocs/lacinia-pedestal/com.walmartlabs.lacinia.pedestal.html#var-inject ^^!

erwinrooijakkers 2019-09-18T08:33:19.008300Z

Thanks @lennart.buit

erwinrooijakkers 2019-09-18T08:33:27.008700Z

So I should not use conj but inject instead?

erwinrooijakkers 2019-09-18T08:33:43.009100Z

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

erwinrooijakkers 2019-09-18T08:34:12.009400Z

And only check the JWT signature once

erwinrooijakkers 2019-09-18T10:12:11.010600Z

This works:

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

gklijs 2019-09-18T10:56:14.010700Z

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

erwinrooijakkers 2019-09-18T14:08:11.011100Z

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

erwinrooijakkers 2019-09-18T14:08:49.011500Z

This one is probably better:

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

erwinrooijakkers 2019-09-18T14:40:50.011700Z

Hmm also too late 😕

erwinrooijakkers 2019-09-18T14:40:53.011900Z

Or too early

erwinrooijakkers 2019-09-18T14:41:23.012500Z

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?

erwinrooijakkers 2019-09-18T14:43:07.012900Z

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))))}))

erwinrooijakkers 2019-09-18T14:44:04.013600Z

I want to use the added context in a resolver

erwinrooijakkers 2019-09-18T14:44:05.013800Z

Like this:

erwinrooijakkers 2019-09-18T14:45:09.014700Z

(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)})