-
I've tried to implement graphql-sse in a react application with vite as you can see here: The react application is a test to verify a successfull graphql SSE subscription, which I have confirmed works from the backend with a graphiql playground. The graphql subscription successfully connects as a SSE connection, which I can see in the terminal, and it receives the expected events in the terminal. But, none of the events show up in the code, where I expect the 'next' function to receive each event and log it to the console. The code only confirms a successfull connection. To describe the steps:
![]() ![]() ![]() ![]()
The problem is replicable using this branch: Steps to boot up everything (need python, node and docker):
Graphql subscription (test out in playground and starts in the react app automatically):
Graphql mutation to send an event (run in the playground at http://localhost:8181/graphql):
I really appreciate any help here! Best regards. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Hey there, there must be an issue with the app. By glancing over it, I see that you're calling |
Beta Was this translation helpful? Give feedback.
-
Hi! I've also experience same problem - nothing in output with basic examples of wundergraph-sse server and graphql-sse client in browser application I'm using wundergraph-sse example to have simple sse subscription with graphql: client code is small and simple: import { Client, createClient, RequestParams } from "graphql-sse";
const client = createClient({
url: 'http://localhost:9991/graphql',
on: {
connecting: () => console.log('client connecting'),
connected: () => console.log('client connected'),
message: (message) => console.log('client message', message),
}
});
const subscription = client.subscribe({
query: `subscription {
sse_greetings
}`
}, {
next: (data) => {
console.log('data', data);
},
error: (error) => {
console.error('error', error);
},
complete: () => {
console.log('complete');
}
}); I've tried several different examples you provided - with async iterator and subscription but non of them looks like have any effect. ![]() ![]() ![]() So maybe there is some compatibility issue with wundergraph's implementation of sse or something else That's is the only output I have from the code above ![]() Would be great if you can give any hint what can be wrong Thanks in advance! |
Beta Was this translation helpful? Give feedback.
-
Given @AlexanderMoroz also tried graphql-sse with Wundergraph (exposing SSE), are you still sure this is not a bug in graphql-sse @enisdenjo? |
Beta Was this translation helpful? Give feedback.
-
@hansehe @AlexanderMoroz, inspecting the messages received over SSE in your screenshots - I noticed that they're malformed coming from the server - they dont have an "event" type specified. There is nothing graphql-sse can do here. The SSE messages for subscription events must specify I reckon graphiql works because it's not using graphql-sse - but is using the plain ol' EventSource and just the on-message handler. You guys should open an issue on the server's repo. |
Beta Was this translation helpful? Give feedback.
@hansehe @AlexanderMoroz, inspecting the messages received over SSE in your screenshots - I noticed that they're malformed coming from the server - they dont have an "event" type specified. There is nothing graphql-sse can do here.
The SSE messages for subscription events must specify
event: next
to be registered by graphql-sse as per the GraphQL over SSE protocol.I reckon graphiql works because it's not using graphql-sse - but is using the plain ol' EventSource and just the on-message handler.
You guys should open an issue on the server's repo.