Skip to content

How to use SSE over HTTP/2 with graphql-yoga? #2225

Answered by aidenfoxx
aidenfoxx asked this question in Q&A
Discussion options

You must be logged in to vote

To answer my own question, it is possible to run yoga under HTTP/2 with some finagling. I was able to get this working under Node 18 using the native fetch implementation. The node-fetch polyfill fails with TypeError: :method is not a legal HTTP header name.

Even then, the ponyfill created by @whatwg-node/fetch seems to be providing the wrong Request class, but this is easily resolved in Node 18 by passing globalThis to fetchApi.

const yoga = createYoga({
  ...
  fetchAPI: globalThis,
});
const server = createSecureServer(
  {
    key: readFileSync("localhost-privkey.pem"),
    cert: readFileSync("localhost-cert.pem"),
  },
  (req, res) => {
    yoga(req as unknown as Request, res);
  }
);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aidenfoxx
Comment options

Answer selected by aidenfoxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant