I just got this to work yesterday so no great expert on this but I think it does what you are asking. I couldn't find a good example online either.
This will trigger a dialog over your views with whatever messages you want. I didn't include the dialog code but it lives in my messagesService.
Notice that I left InMemoryCache in there as a note for responses such as this that it isn't needed. It is included in Boost and setup automatically. I was able to read it with readQuery.
I went with Boost and I put it in app.module in the exported class because I couldn't get it to work above in the module providers. Originally I was setup like you did but reaching the messagesService didn't work out. It could also be a service and I may move it there. This is global and you don't have to do anything in your components. Very nice!
app.module.ts
export class AppModule {
// Create and setup the Apollo server with error catching globally.
constructor(
private messagesService: MessagesService,
private apollo: ApolloBoost,
) {
apollo.create({
uri: 'http://localhost:3000/graphql',
// cache: new InMemoryCache(), // This is included by default. Can be modified.
onError: ({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`),
console.log('This is a graphQL error!'),
);
const msg1 = 'GraphQL error';
const msg2 = 'Please contact support.';
this.handleError(msg1, msg2)
}
if (networkError) {
console.log('This is a Network Error!', networkError);
console.log('Can be called from a query error in the browser code!');
const msg1 = 'Network error';
const msg2 = 'Please check your Internet connection. If OK then contact support .';
this.handleError(msg1, msg2)
}
}
});
}
public handleError(msg1, msg2) {
this.messagesService.openDialog(msg1, msg2);
}
}