0

i am trying to fetch data to the client through subscriptions from a graphql server. in order to do so we need to establish a websocket connection first. However when I try to do it i get the following error back

error:

WebSocket connection to 'ws://localhost:8888/' failed: Unexpected response code: 400
liveReload — index.js:53

client side code:

import { WebSocketLink } from "@apollo/client/link/ws";
const wsLink = new WebSocketLink({
  uri: "ws://localhost:8888",
  options: {
    reconnect: false
  }
});

i am 100% certain that localhost:8888 is where the graphql server is hosted.i have tried both in safari and firefox

shauna vayne
  • 159
  • 2
  • 12
  • If you look in the response itself, is there any description of the error? For instance of you look in the network inspector in devtools, you may see more information about the failure. – loganfsmyth May 03 '21 at 16:18
  • Are you sure this API supports websocket connections? – loganfsmyth May 03 '21 at 16:19

1 Answers1

0

you have to specify the subscription path explicitly on the graphql server declaration as below

const server = new ApolloServer({
  typeDefs,
  resolvers,
  subscriptions: {
    **path: "/subscriptions"**
  },
  context: {
    pubsub
  }
});
shauna vayne
  • 159
  • 2
  • 12