This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-08
Channels
- # bangalore-clj (4)
- # beginners (160)
- # calva (132)
- # cider (18)
- # clara (1)
- # cljsrn (2)
- # clojure (129)
- # clojure-boston (1)
- # clojure-europe (5)
- # clojure-italy (5)
- # clojure-losangeles (1)
- # clojure-nl (33)
- # clojure-uk (49)
- # clojurescript (88)
- # cursive (20)
- # datomic (5)
- # duct (3)
- # fulcro (33)
- # graphql (7)
- # jobs (3)
- # kaocha (3)
- # nrepl (41)
- # off-topic (58)
- # pathom (18)
- # re-frame (1)
- # reagent (5)
- # shadow-cljs (148)
- # spacemacs (7)
- # tools-deps (7)
I'm trying to write a plugin which adds an authorization header to graphql requests. This is what I have right now, but it doesn't seem to be adding the header as I expect it would. (I've checked that id-token-str
has the expected value.) Any thoughts on what's going wrong?
(def auth-plugin
{::p/wrap-parser
(fn [parser]
(fn [env tx]
(let [{:keys [id-token-str]} @auth]
(parser (cond-> env
(seq id-token-str)
(assoc-in [::p.http/headers :authorization] (str "Bearer " id-token-str)))
tx))))})
(def parser
(p/parallel-parser
{::p/env {::p/reader [p/map-reader
pc/parallel-reader
pc/open-ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}
::p.http/driver p.http.fetch/request-async}
::p/mutate pc/mutate-async
::p/plugins [(pc/connect-plugin {::pc/indexes indexes})
auth-plugin
p/error-handler-plugin
p/request-cache-plugin
p/trace-plugin]}))
hello @codonnell, I don't see any graphql integration in your setup, usually the request for that is part of this integration, or just you just mean regular http calls?
Was trying to avoid pasting a whole bunch of code; I'll include a snippet with all of the relevant code.
@wilkerlucio I did mean graphql; I'm using the connect integration.
@codonnell gotcha, ok, so your setup looks correct, are you able to load the graphql schema without providing the auth? that's the only place I see that would not go though the plugin and so would miss the auth
Oh derp, that is exactly the problem.
Thanks 😄
Never mind, that was a problem. Still not seeing the authorization header get added when I move the schema fetching to after I add the token value.
Updated init
I believe this new setup still doesn't send the auth, because it doesn't go though the parser, so you have to add the headaer in the my-gql
when sending to load index
I did check the code, the env is send though from the parser to the gql, so I believe it will work once there
another important thing to notice is that the specific namespaces are important on the connect integration
so since your prefix is ::pcg/prefix "little-gift-list.type"
, every attribute must start with that
so in the GiftList
for example, instead of :query [::gift/id ::gift/name
you probably want :query [:ittle-gift-list.type.gift/id :ittle-gift-list.type.gift/name ...
ah, nevermind, I just realised you did proper alias for those, nice 🙂
probably still an issue with the load-index
Ah of course, that makes sense. I replaced (pcg/load-index my-gql indexes)
with (pcg/load-index (assoc-in my-gql [::p.http/headers :Authorization] (str "Bearer " (-> auth/auth deref :id-token-str))))
and can confirm that the header is added. Thanks for the help!
Is there a way to coerce values that come back in graphql responses? For example, I have uuids and timestamps which are encoded as json strings that I'd love to convert to uuid/datetime types before transacting them into my app db.