I'm sending request headers through graphiql subscriptions
I can't get those variables here through backend
using lacinia-pedestal 1.1
my :request inside :context only comes with: :id, :query, :response-data-ch, :shutdown-ch, :variables
anyone knows how can I assoc headers through a request through graphiql??
@d.ian.b seems to be related with the fact that in pedestal websockets, there is no (or just a few) "context" from request on websocket handlers. https://github.com/pedestal/pedestal/blob/master/samples/jetty-web-sockets/src/jetty_web_sockets/service.clj#L58
this was not the answer, btw he opened a PR
https://github.com/walmartlabs/lacinia-pedestal/pull/129/files
I already handled that in pedestal once. I digging lacinia-pedstal to see how I can do it
(lp/default-service schema {:init-context (fn [ctx req res]
;; original:
#_ctx
;; with request/headers:
(merge ctx req {:check-if-init-context-works 42}))})
in default-service there is a call only for :app-context not for :init-context is this right?
options as second argument of enable subscriptions https://github.com/walmartlabs/lacinia-pedestal/blob/master/src/com/walmartlabs/lacinia/pedestal2.clj#L364 then as last in add-subscriptions support https://github.com/walmartlabs/lacinia-pedestal/blob/master/src/com/walmartlabs/lacinia/pedestal2.clj#L319 last in listener-fn-factory https://github.com/walmartlabs/lacinia-pedestal/blob/master/src/com/walmartlabs/lacinia/pedestal/internal.clj#L276 finally, init-context https://github.com/walmartlabs/lacinia-pedestal/blob/master/src/com/walmartlabs/lacinia/pedestal/subscriptions.clj#L543
anyway, should be easy to test if the :check-if-init-context-works key show up in the context
sure
Thanks
trying it right now
req and res do not come here
ServletUpgradeRequest
(lp/default-service schema {:init-context (fn [ctx ^org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest req res]
;; original:
#_ctx
;; with request/headers:
(assoc ctx
:headers (into {}
(map (fn [[k vs]]
[k (string/join "," vs)]))
(.getHeaders req))))})
The thing is that I can't capture the headers in a request when I do subscriptions on Lacinia...
Anyone here got this working?
@d.ian.b did you try passing anything for the context in lacinia/execute?
he is using lacinia-pedestal, so he didn't call lacinia/execute directly
but yes, do not use lacinia-pedestal is a possible solution