Fork me on GitHub
#graphql
<
2022-06-30
>
Ian Fernandez00:06:17

I'm sending request headers through graphiql subscriptions

Ian Fernandez00:06:30

I can't get those variables here through backend

Ian Fernandez00:06:36

using lacinia-pedestal 1.1

Ian Fernandez00:06:37

my :request inside :context only comes with: :id, :query, :response-data-ch, :shutdown-ch, :variables

Ian Fernandez00:06:01

anyone knows how can I assoc headers through a request through graphiql??

souenzzo14:06:31

@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

1
souenzzo14:06:09

I already handled that in pedestal once. I digging lacinia-pedstal to see how I can do it

souenzzo14:06:05

@d.ian.b

(lp/default-service schema {:init-context (fn [ctx req res]
                                            ;; original:
                                            #_ctx
                                            ;; with request/headers:
                                            (merge ctx req {:check-if-init-context-works 42}))})

1
Ian Fernandez15:06:08

in default-service there is a call only for :app-context not for :init-context is this right?

souenzzo15:06:05

anyway, should be easy to test if the :check-if-init-context-works key show up in the context

sheepy 1
Ian Fernandez15:06:08

trying it right now

Ian Fernandez15:06:58

req and res do not come here

souenzzo01:07:17

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

oliy07:07:40

^ this is most probably your answer @d.ian.b I was trying to find it yesterday and couldn't, thanks @U2J4FRT2T

Ian Fernandez13:07:20

this was not the answer, btw he opened a PR

Ian Fernandez17:06:43

The thing is that I can't capture the headers in a request when I do subscriptions on Lacinia...

Ian Fernandez17:06:52

Anyone here got this working?

isak22:06:09

@d.ian.b did you try passing anything for the context in lacinia/execute?

souenzzo00:07:50

he is using lacinia-pedestal, so he didn't call lacinia/execute directly

1
souenzzo00:07:05

but yes, do not use lacinia-pedestal is a possible solution