Hi, I’ve been trying to incorporate subscriptions into the aforementioned stack (the React bit is irrelevant since this issue is regarding the back-end) but I’ve just been coming across many ways of incorporating subscriptions but I can’t seem to figure out how to integrate it into my already existing Meteor app.
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 understand from the Apollo docs that I should use a PubSub
class from another library and not the standard one they show in the docs, and I decided to try Redis
.
I have tried declaring this new PubSub object and passing that in via the ApolloServer context
but when I test out my subscription in Graphiql I get the following error (IP masked):
{
"error": "Could not connect to websocket endpoint ws://XXX.XXX.XX.XX:3000/subscriptions. Please check if the endpoint url is correct."
}
And in my terminal this prints every second or two:
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
}
So clearly I am missing some configuration step, but I’ve not been able to figure out why. Any help would be appreciated, thank you.
EDIT: I tried GooglePubSub
instead and now the last error isn’t thrown anymore in my terminal, but the error in Graphiql persists.