I’m using ApolloClient with nextjs and some getStaticProps configured for ISR. I keep running in to a situation where it crashes my entire server when I get an error, or at least that’s what I assume is happening, based on logs - it always puts out an ApolloClient error, then crashes the server.
How can I make sure an ApolloClient error doesn’t knock out the whole server?
This is my configuration:
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
),
);
if (networkError) console.log(`[Network error]: ${networkError}`);
});
function createApolloClient() {
const linkBase = [errorLink];
if (typeof window !== "undefined") {
linkBase.push(apolloLogger);
}
return new ApolloClient({
ssrMode: typeof window === "undefined",
link: ApolloLink.from([
...linkBase,
createPersistedQueryLink({
sha256,
useGETForHashedQueries: true,
}),
createHttpLink({
uri: process.env.NEXT_PUBLIC_GQL_API_URL,
credentials: "include",
}),
]),
cache: new InMemoryCache({
addTypename: true,
typePolicies: {
...
},
}),
});
}