When handling a graphQL error in the client, it’s useful to be able to understand in a large system where the issue came from. When using the Error Link, you can access stacktrace information from the ApolloServer, but I want to be able to see call-site information from the client. Ideally to send to Sentry.
In ApolloClient links, creating a stacktrace and logging it will only return the stacktrace of the Apollo link system, which is not particularly helpful.
e.g.
const testLink = setContext(() => {
const err = new Error();
console.log('IM HERE', err.stack);
return {};
});
return new ApolloClient({
link: ApolloLink.from([testLink, errorLink]),
}
IM HERE createApolloClient/testLink<@webpack-internal:///./src/services/ApolloService.ts:56:25
setContext/</</<@webpack-internal:///../node_modules/@apollo/client/link/context/index.js:18:47
It’s possible to log the name of the GraphQL query, which is helpful when all queries have a unique name, but unfortunately that is not the case in our large codebase.
Is there a way to add the location of where the graphQL query originated from within the client to the error log in the ApolloClient error link? Or am I just approaching this incorrectly?