Why subscription example from the official docs is not working correctly?

No problem, I appreciate you taking the time to help! And yes the createUser mutation is working without any errors

Hmm that’s so strange! Have you tried the following order of operations?

Starting from the top:

  1. Run the newUserCreated subscription operation and it begins to “listen” for updates
  2. Run the createUser mutation
  3. The “listening” newUserCreated subscription receives and returns the new user

With this order of operations do you get any more interesting errors?

I figured out the problem and your first hunch was right. I had my graphql settings wrong under the subscriptions setting. The first screenshot I showed you I had the Subscriptions url set to “wss://localhost:3001/graphql” when it should have been “ws://localhost:3001/graphql”.

1 Like

Awesome! I’m so glad you figured it out and it’s working. :star2:

Me too! Again thanks for taking the time to help!

Thanks, @StephenBarlow now it works, after weeks of reading and searching. this should be urgently included on the documentation page as a tip note. Also, this post should be labelled as solved so anyone who has the same issue can find it easily.

Hi I am experiencing a similar issue using the base example (https://github.com/apollographql/docs-examples/blob/main/apollo-server/v4/subscriptions-graphql-ws/src/index.ts). I have implemented exactly as is (copy & paste). I have tried using the ws and wss protocals on the apollo client. I am getting an error " Unable to reach subscription server". When I try to run the

npx diagnose-endpoint@1.1.0 --endpoint=ws://localhost:4000/graphQL

command it displays:
Diagnosing ws://localhost:4000/graphQL
:warning: Could not resolve (ENOTFOUND)
Is the address correct?
Is the server running?

Can someone please advise?