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 ^^!
Thanks @lennart.buit
So I should not use conj
but inject
instead?
I prefer an interceptor to avoid the deep destructuring of the request in every method
And only check the JWT signature once
This works:
(defn interceptors [schema]
(let [opts {}]
(pedestal/inject (default-interceptors schema opts)
roles-interceptor
:before
::pedestal/json-response)))
Thanks for posting the solution, might wanna implement something like it myself.
Hmm it actually does not work properly, it is too late 🙂
This one is probably better:
(defn- inject-roles-interceptor [interceptors]
(log/info interceptors)
(pedestal/inject interceptors
roles-interceptor
:after
::pedestal/inject-app-context))
Hmm also too late 😕
Or too early
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?
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))))}))
I want to use the added context in a resolver
Like this:
(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)})