-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOMException: Failed to construct 'WebSocket': The URL '/graphql' is invalid. #16
Comments
This error is due to a discrepency between URLs recommended to use for queries in the playground: Even though Given the earlier setup of http to test graphql queries, it would follow that ws:// would be the place to test subscriptions, but the purpose of mentioning ws:// is not clear. So, the above error was made more confusing by the mention of The text of the books states: "By default, Apollo Server sets up a WebSocket at ws://localhost:4000. If you use the simple server configuration that we demonstrated at the beginning of Chapter 5, you’re using a configuration that supports WebSockets out of the box."* @eveporcello can you please clarify? *Porcello, Eve; Banks, Alex. Learning GraphQL: Declarative Data Fetching for Modern Web Apps (Kindle Locations 3886-3887). O'Reilly Media. Kindle Edition. |
Now, I've switched to using
I'll continue to update until I hear back, or until I fix the issue. Any help is appreciated. |
In general, this book is very good and specific up to chapter 7, then there are a few discrepancies. The above is one small example where more clarity is needed, but then the App.js code diverges from the previous example when Posting Photos is added as an example: App.js from github repo "chapter-07"
The above code follows the previous example in the book, but the App.js code below as it's suggested in the book in the postPhoto example does not contain the same or similar code:
As you can see, there's no |
I'll take a look and get back to you - thanks. |
Check out your app.get('/playground', expressPlayground({
endpoint: '/graphql',
subscriptionEndpoint: '/graphql' // just add this line
})) Regarding this passage: "By default, Apollo Server sets up a WebSocket at ws://localhost:4000. If you use the simple server configuration that we demonstrated at the beginning of Chapter 5, you’re using a configuration that supports WebSockets out of the box." ^^ We say that because if you use the simple Apollo Server from Chapter 5 ( Let me know how that goes. I'll leave the issue open in the meantime. |
@eveporcello thanks, but let me ask a potentially dumb question just to make it clear what I'm struggling to understand: Am I supposed to be able to see the graphql playground or something else when I enter ws://localhost:4000/ into the browser address bar and press return? I'd think that address would be used to test subscription queries in the same way http queries can be tested via http://localhost:... I followed the instructions from the book and added the |
Not a dumb question! If you go to ws://localhost.., you won’t see anything. If you want to test subscriptions, you should go to http://localhost:4000/playground. Then you’ll run a subscription in one tab and you’ll run a mutation in another tab and you can flip back to the subscription and see the changes. Let me know how that goes! |
Ah, thanks. So, would the purpose of pointing to that address be to say, the browser uses this address for websockets, but it doesn't work as http does in the address bar because it's not publicly exposed? |
Yes exactly! 😀
… On Oct 30, 2018, at 8:58 AM, brianebill ***@***.***> wrote:
Ah, thanks.
So, would the purpose of pointing to that address be to say, the browser uses this address for websockets, but it doesn't work as http does in the address bar because it's not publicly exposed?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@eveporcello thanks for the clarifications :) Good luck on the workshops. |
Actual behavior: After cloning chapter 7 and
npm install
thennpm start
the above error occurs when running the following query in /playground:subscription { newPhoto { name url postedBy { name } } }
I was encountering the same error after following the directions in the book.
Also
ws://localhost:4000/
does not connect, with the browser statingThis site can’t be reached
Expected behavior: When the instructions are followed in the book, or when the repo is cloned and started, there should be no errors.
I suspect this has to do with new npm packages being released, but am seeking clarity as the repo seems to have been created 4 months ago with updates as recently as 2 months ago.
The text was updated successfully, but these errors were encountered: