Hi, I’m carrying on the discussion from where it was left off in this thread.
I am running a Meteor/React/Apollo/Graphql stack, and require Graphql subscriptions. As such, the only way I found so far to get this done is by using the swydo:ddp-apollo package.
However, what I observed is that all operations (queries, mutations, subscriptions) use the WebSocket connection (screenshot from the Chrome Dev Tools Network tab):
How scalable would something like this be? I imagine this is not good practice to have a WebSocket connection open for every single user on the site.
Ideally what I need to be able to do is split the query based on whether it’s a subscription or query/mutation and have that hit the localhost:3000/graphql
endpoint. But there are some problems with this:
- I have not found a way to use the server code provided as per the DDP-Apollo docs AND have Graphiql available at
/graphql
.
setup({
schema
})
- If I use my old server code, Graphiql is available but I’m unable to subscribe to anything because
ws://localhost:3000/subscriptions
is not a websocket endpoint.
const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
const context = async ({req}) => ({
user: await getUser(req.headers.authorization)
})
const server = new ApolloServer({
schema,
context,
subscriptions : {
path: '/subscriptions'
}
})
server.applyMiddleware({
app: WebApp.connectHandlers,
path: "/graphql",
})
WebApp.connectHandlers.use("/graphql", (req, res) => {
if (req.method === "GET") {
res.end()
}
})
I’ve spent many days on this and searched in many places but I’ve not been able to find a proper solution to this. Would appreciate any help!