Hey people, I have a server side subscription that...
# prisma-whats-new
t
Hey people, I have a server side subscription that works great for a while, but eventually (hours, a day perhaps), will just stop executing. I'm using
subscriptions-transport-ws
and the documentation mentions a keep-alive. Does anyone know where graph cool utilizes a keep alive with it's subscription endpoints?
n
you say server side subscription but say subscriptions-transport-ws. those two are mutually exclusive. can you share your client version and configuration?
t
Ah, right--server-side subscriptions refer to the graphcool server functions? Client version is apollo-client 1.9.3
Config:
Copy code
import { ApolloClient, createNetworkInterface } from 'apollo-client';
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws';
import ws from 'ws';
import config from '../config';

const wsClient = new SubscriptionClient(
   config.graphcool.subscriptionsUri,
   {
      reconnect: true
   },
   ws
);

const networkInterface = createNetworkInterface({
   uri: config.graphcool.uri
});

const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(networkInterface, wsClient);

networkInterface.use([
   {
      applyMiddleware(req, next) {
         // Create the header object if needed.
         if (!req.options.headers) {
            req.options.headers = {};
         }

         req.options.headers.authorization = `Bearer ${config.graphcool.token}`;
         next();
      }
   }
]);

export default new ApolloClient({
   networkInterface: networkInterfaceWithSubscriptions
});