graphql 2022-06-30

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

🤔 1

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

this was not the answer, btw he opened a PR

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

@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

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

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

1

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

👌🏻 1

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