Apollo-server: Need context access in formatError

Created on 21 Feb 2019  路  5Comments  路  Source: apollographql/apollo-server

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?

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!

All 5 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nevyn-lookback picture nevyn-lookback  路  3Comments

Magneticmagnum picture Magneticmagnum  路  3Comments

manuelfink picture manuelfink  路  3Comments

dupski picture dupski  路  3Comments

dbrrt picture dbrrt  路  3Comments