enisdenjo / graphql-sse

Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client.
https://the-guild.dev/graphql/sse
MIT License
384 stars 19 forks source link

No response from subscription in React code. #104

Closed hansehe closed 1 month ago

hansehe commented 1 month ago

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:

  1. The SSE subscription works well in the graphiql playground: sse_problem_1 sse_problem_2

  2. The same SSE subcription should work with graphql-sse in react, and it successfully connects and receives events on the connection seen in the terminal:

    sse_problem_3 sse_problem_4 sse_problem_5 sse_problem_6
  3. But none of the events (as they have been received on the connection as seen in the terminal), are handled by the code.

The problem is replicable using this branch:

Steps to boot up everything (need python, node and docker):

pip install DockerBuildManagement
# Run bakground services which are stitched togheter by the wundegraph graphql gateway - Note: the services are compiled for amd64
dbm -swarm -start
# Build and run the graphql gateway (wundergraph)
dbm -build -run service
# The graphql gateway is hosted on http://localhost:8181/graphql

# Run React client
cd ./client/sse-client
npm ci
npm run dev
# hosted on http://localhost:3001

Graphql subscription (test out in playground and starts in the react app automatically):

subscription {
  mqttSubscription {
    payload
  }
}

Graphql mutation to send an event (run in the playground at http://localhost:8181/graphql):

mutation {
  mutateMqtt {
    topics
  }
}

I really appreciate any help here!

Best regards. Hans Erik