Search code examples
asp.netwebsocketgraphqlvisual-studio-machotchocolate

Websocket connection to Hot Chocolate GraphQL server fails in local environment


Hello Hot Chocolate Community,

I'm having trouble setting up websockets for my Hot Chocolate GraphQL server in my local environment. I have followed the documentation and added app.UseWebSockets() to my ASP.NET Core application, which is running on my local machine. However, when I try to connect to the websocket at ws://localhost:7217/graphql/ using wscat, I get the error "socket hang up". Similarly, when I try to connect from my React app using Apollo Client, I get the error "websocket connection to 'ws://localhost:7217/graphql/ws' failed".

I would appreciate any help in figuring out what is causing the issue. Here are some additional details:

  • I'm using Hot Chocolate version 13
  • I'm running the server on macOS and testing with wscat on the command line
  • I am starting the server via visual studio for mac
  • I have not made any other changes to my application's configuration
  • I'm able to make regular HTTP requests to the server and receive valid responses

Thank you for your assistance.


Solution

  • So after a lot of investigation and texting with the hotchocolate stuff, which indeed is very open to help. (Checkout there Slack channel).

    I tried again via Apollo Client and checked how the connection got established via Banana Cake Pop: They use wss instead of ws, which is great for me.

    So I could establish the connection with apollo client by switching the uri to wss