How are graphql errors getting displayed through snackbar ?
I tried looking at Errorlink implementation in Apollofactory, which handles different kind of errors. There is this switch case for UNAUTHENTICATED error extension code which has been handled and for other cases I think we are getting that error snackbar but I dont see any snackbar function getting invoked for that nor I could find a state for it. So is it something internally handled by apollo client ?
Where there is a case for UNAUTHENTICATED, I want to add one more case and want to show a descriptive message in snackbar for that. Because right now it is displaying “Error” or “GraphQLError” as per what I return from backend.
9 Replies
I believe, the unauthenticated error is not triggering a snack bar
to use the snackbar you can look for: const { enqueueSnackBar } = useSnackBar(); in the coe
You need to be in the <SnackBarProvider> context (take a look at index.tsx) to be able to use it though
Hi @charles I have used useCreateOneRecord hook to create one record and it is failing so I can see the GraphQLError snackbar. But instead of GraphQLError I need to display a custom message; so to achieve this,is it a right decision to add condition in errorLink ? Because if I were to edt ErrorLink implementation somehow then I will need to invoke useSnackbar and I dont think I can use that in ApolloFactory class.
I think we should imporve the way error messages are enqueue globally (it's on our roadmap for May). The errorMessage should be spciefied in the backend and nicely displayed in the FE
Could you create a ticket on github with your specific usecase and we will make sure to provide a global solution in the app. For now, I think you can indeed play with errorLink in apolloClient.ts but we should come with a nicer solution
Understood. Will raise a ticket and the patch you explained, it worked for me and I was even able to kind of make a generic errorhandler for such cases which will display error messages coming from backend. Its a patch though not a solution. Still I am facing one issue, I was able to open the snackbar for specific errors but still I am getting that “GraphQLError” snackbar. So in conclusion Now I am getting two errors. If you could tell me from where that error is getting initiated or maybe steps to debug then it would be a great help.
I tried to find but I couldn’t find where this GraphQLError snackbar is coming from
If you want to reproduce this issue then try with useCreateOneRecord and make sure you get error from backend for that operation.
yes, you'll see that useCreateOneRecord is calling the enqueueSnackBar itself, I think that's why
Actually “useCreateOneRecord” is not calling enqueSnackbar. But anyway The issue got resolved, the snackbar was from my catch block 😁. Sorry for the trouble man !
sounds good!