Skip to content
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

Could not connect to WebSocket endpoint #28

Open
ajaypillay opened this issue May 9, 2021 · 0 comments
Open

Could not connect to WebSocket endpoint #28

ajaypillay opened this issue May 9, 2021 · 0 comments

Comments

@ajaypillay
Copy link

Hi, I'm running a Meteor/React/Apollo/Graphql stack and I'm trying to get subscriptions working, I've looked through the Apollo docs and have tried to get it working with this library but I'm getting an error in my Graphiql console as such:

{
  "error": "Could not connect to websocket endpoint ws://XXX.XXX.XX.XX:3000/subscriptions. Please check if the endpoint url is correct."
}

My server code is as follows:

import { ApolloServer, gql } from "apollo-server-express"
import { makeExecutableSchema } from "graphql-tools"
import { WebApp } from "meteor/webapp"
import { getUser } from "meteor/apollo"
import merge from "lodash/merge"

import SchemaA from "../../api/a/SchemaA.graphql"
import ResolverA from "../../api/a/resolvers"
import SchemaB from "../../api/b/SchemaB.graphql"
import ResolverB from "../../api/b/resolvers"
import SchemaC from "../../api/c/SchemaC.graphql"
import ResolverC from "../../api/c/resolvers"

import { GooglePubSub } from "@axelspringer/graphql-google-pubsub"

const pubsub = new GooglePubSub()

const typeDefs = [SchemaA, SchemaB, SchemaC]
const resolvers = merge(ResolverA, ResolverB, ResolverC)

const schema = makeExecutableSchema({ typeDefs, resolvers })

const server = new ApolloServer({
    schema,
    context: async ({ req }) => ({
        user: await getUser(req.headers.authorization),
        pubsub
    }),
    subscriptions : {
        path: '/subscriptions'
    }
})

server.applyMiddleware({
    app: WebApp.connectHandlers,
    path: "/graphql",
})

WebApp.connectHandlers.use("/graphql", (req, res) => {
    if (req.method === "GET") {
        res.end()
    }
})

I had initially tried this exact setup with the Redis pubsub alternative but I was getting the following error in my terminal:

Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}

I'm not getting this error anymore with GooglePubSub, but the first error thrown in Graphiql still persists. Does anyone have any recommendations on how to go about fixing this? There's clearly some configuration/setup which I'm not doing correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant