6

Having a bit of trouble with keepAlive for Apollo subscriptions. When ever I set a time to seconds or more the listening subscriptions errors out.

{
  "error": "Could not connect to websocket endpoint ws://website.test:8000/graphql. Please check if the endpoint url is correct."
}

Here is ApolloServer setup

const apollo = new ApolloServer({
    introspection: true,
    playground: true,
    typeDefs: schema,
    subscriptions: {
      keepAlive: 40000,
    },
    resolvers,
    context: ........
}

In my local environment when I do not set keepAlive it will stay open indefinitely. If I set it at 10000 works great. With keep alive set at 40000 I get the error and connection closes

UPDATE One thing we just noticed is that this issue happens on the playground but not on our web app. Maybe just a playground thing?

Daniel Dodd
  • 93
  • 1
  • 5

2 Answers2

1

If you check the documentation provided by Apollo GraphQL:

keepAlive - Number

The frequency with which the subscription endpoint should send keep-alive messages to open client connections, in milliseconds, if any.

If this value isn't provided, the subscription endpoint doesn't send keep-alive messages.

As per your provided configuration, with keep alive set at 40000, this is equivalent to 40 seconds. So the subscription endpoint is pinging keep-alive messages every 40 seconds. This probably is too long and the connections is already closed.

You should use a smaller value

Julius A
  • 38,062
  • 26
  • 74
  • 96
0

If none if these help I suggest you open a issue on the Apollo repository:

tscpp
  • 1,298
  • 2
  • 12
  • 35
  • Changing the timeout to 10 seconds instead of 40 fixes the issue for me so I don't think it's anything todo with general web socket timeouts. It seems Apollo related. Apollo tends to point people back to stack overflow so opening an issue there likely isn't to help. Also none of these look like they're related to the issue. – Alexis Tyler May 03 '21 at 06:02