I basicely created express server and then added SubscriptionServer.
/*
* GRAPHQL SERVER
*/
const graphqlServer = express()
graphqlServer.use(cors())
graphqlServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema: schema }))
graphqlServer.get('/graphiql', graphiqlExpress({ endpointURL: '/graphql', subscriptionsEndpoint: `ws://localhost:${process.env.GRAPHQL_PORT}/subscriptions`, }))
graphqlServer.listen(process.env.GRAPHQL_PORT, () => {
SubscriptionServer.create(
{
schema,
execute,
subscribe,
},
{
server: graphqlServer,
path: '/subscriptions',
},
)
console.log(`
- GraphQL server listening on http://localhost:${process.env.GRAPHQL_PORT}
- GraphQL subscriptions listening on ws://localhost:${process.env.GRAPHQL_PORT}/subscriptions
`)
})
Than when I tryied to connect on GraphQLi subscriptions server it throwed an error.
WebSocket connection to 'ws://localhost:10005/subscriptions' failed: Connection closed before receiving a handshake response
I do not know what that mean nor where is problem.
If anyone did similar project it would be super helpful to maybe send me github link :)
Thanks a lot