This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-18
Channels
- # announcements (26)
- # beginners (107)
- # calva (26)
- # cider (55)
- # clj-kondo (7)
- # clojure (115)
- # clojure-europe (6)
- # clojure-houston (3)
- # clojure-italy (4)
- # clojure-nl (16)
- # clojure-norway (1)
- # clojure-uk (42)
- # clojuredesign-podcast (3)
- # clojurescript (47)
- # clojutre (4)
- # cursive (7)
- # datomic (75)
- # fulcro (1)
- # graalvm (3)
- # graphql (16)
- # jobs (1)
- # jobs-discuss (13)
- # keechma (1)
- # leiningen (19)
- # luminus (5)
- # off-topic (33)
- # pathom (16)
- # re-frame (76)
- # reitit (4)
- # ring (5)
- # shadow-cljs (86)
- # spacemacs (52)
- # tools-deps (43)
- # vim (7)
- # yada (1)
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 ^^!
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)))
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)})