I’ve got an Apollo Server the works with redis. Every so often redis times out and that causes my apollo graphql server (running in docker) to crash and not start again.
I get the message “app crashed - waiting for file changes before starting”
How can I catch that error and just simply console log it and continue processing requests?
Here is what I have for my index.js (many details removed)
async function startApolloServer(typeDefs: any, resolvers: any) {
const app = express();
const httpServer = http.createServer(app);
const cacheDefaultMs = parseInt(process.env.GRAPHQLSERVERREDISTIMEOUT ?? 0);
const redisHost = process.env.REDISHOST ?? "localhost";
const redisPort = process.env.REDISPORT ?? 6379;
const graphqlCacheEnabled =
process.env.GRAPHQLCACHEENABLED === "true" ?? false;
const server = new ApolloServer<MyContext>({
typeDefs,
resolvers,
csrfPrevention: true,
cache: graphqlCacheEnabled === true ? new KeyvAdapter(keyV) : undefined, // for redis
plugins: [
responseCachePlugin(), // for redis
ApolloServerPluginDrainHttpServer({ httpServer }),
],
});
require("dotenv").config();
const version =
process?.env?.RELEASEVERSION ?? "process?.env?.RELEASEVERSION";
const releaseDate = process?.env?.RELEASEDATE ?? "process?.env?.RELEASEDATE";
await server.start();
);
await new Promise<void>((resolve) =>
httpServer.listen({ port: 4000 }, resolve)
);
console.log(`🚀 Server ready at http://localhost:4000/graphql`);
}
startApolloServer(typeDefs, resolvers);