Applies to: apollo-server-hapi (and probably more)
The formatError function which you can pass into ApolloServer when starting has no way to gain access to context (or request). In previous versions (the old graphql-server-hapi), we had access to this. In our workflows, this is necessary because we log these errors using the request log (which we have access to in context) and then mask the errors going back to the client them depending on the environment. Is there any way you could add the capability to access context as an argument to this function?
We have the same issue with express. We use the context to know in which language the error should be translated.
It would be awesome to have it as a second argument.
@BigMaster Awesome! That's definitely a helpful workaround to get a usable error formatter. I would still love to see it be a part of the actual exposed function from apollo-server though. Doubly so because I believe the one apollo exposes is actually created the same way that the one you created is!
formatError isn't the right place to report errors from, but we've recently exposed a didEncounterErrors function as part of the new request pipeline API: https://github.com/apollographql/apollo-server/pull/2719
Awfully light on documentation on that one, lol
@martijnwalraven The errors of this hook are readonly, what if you need to modify errors with information from the context?
Most helpful comment
@BigMaster Awesome! That's definitely a helpful workaround to get a usable error formatter. I would still love to see it be a part of the actual exposed function from apollo-server though. Doubly so because I believe the one apollo exposes is actually created the same way that the one you created is!