not finding websocket with subscriptions
See original GitHub issueWriting a simple chat application using apollo and express. Prior to this I was using subscriptions-transport-ws and graphql-server-express but there was an issue with graphiql not being able to call subscriptions due to a client error with graphiql. Because of this issue, I swapped over to apollo.
Currently, when I try to access a subscription through graphiql the client comes back and says:
"Could not connect to websocket endpoint ws://localhost:6001/graphql. Please check if the endpoint url is correct."
If I try to use a simple websocket client to find the websocket endpoint, it doesn’t seem to exist.
I stripped out most of the stuff from my server/index.js file to see if I could solve this problem, heres what it looks like:
import { createServer } from 'http'
import express from 'express'
import { typeDefs } from './types'
import resolvers from './resolvers'
import { ApolloServer } from 'apollo-server-express'
const PORT = process.env.PORT || 6001
const app = express()
const apollo = new ApolloServer({
typeDefs,
resolvers
})
apollo.applyMiddleware({ app })
const httpServer = createServer(app)
apollo.installSubscriptionHandlers(httpServer)
app.listen({ port: PORT }, () => {
console.log(`server ready at http://localhost:${PORT}${apollo.graphqlPath}`)
console.log(`Subscriptions ready at ws://localhost:${PORT}${apollo.subscriptionsPath}`)
})
My imports in package.json look like this:
"dependencies": {
"apollo-server": "^2.1.0",
"apollo-server-express": "^2.1.0",
"bluebird": "^3.5.2",
"body-parser": "^1.18.3",
"compression": "^1.7.3",
"cors": "^2.8.4",
"express": "^4.16.4",
"graphql": "^14.0.2",
"graphql-playground-middleware-express": "^1.7.6",
"graphql-subscriptions": "^1.0.0",
"graphql-tools": "^4.0.2",
"mongoose": "^5.3.4"
},
Not really sure why the subscription endpoint isn’t properly being deployed through the apollo.installSubscriptionHandlers(httpServer)
command.
Issue Analytics
- State:
- Created 5 years ago
- Comments:24
Top GitHub Comments
Never mind, figured it out right after I posted this.
Had the same issue, console was showing 400 error. Adding highlighted line from this article solved problem for me. https://www.apollographql.com/docs/apollo-server/data/subscriptions/#subscriptions-with-additional-middleware