Apollo-server: [feature] async formatResponse and formatError

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

Hooks formatResponse and formatError do not accept async operations.
Tools that report errors are difficult to use because formatError does not support async operations.
I particularly need to perform some operations with each graphql response, I can not because formatResponse is not async.

I'm doing tests and adjustments and I intend to send a PR soon, before I'm starting a dialogue about it.

Related #1748

Most helpful comment

All 9 comments

I'm running into an issue with with AWS Lambda. I am sending my error to sentry inside formatError but this is an asynchronous operation so there is a chance that the function will close before the message is sent.

Same!

Same

Same. I need some data from cache or db to decorate response. How can I do it without async support?!

Any workaround for this? I need to make an http call (apollo-rest-datasource) under certain conditions before returning response (formatResponse).

Couldn't find any other Apollo Server function that executes after all resolvers are resolved.

I actually am using Sentry too to report any error occuring in formatError function, but errors are generally sent so I didn't except to have a problem with this until reading this issue.

@vinicius73 any news here? I am facing the same issue...

@dunika My problem is exactly the same, using a very similar stack. Were you able to solve it?

This should be possible by using the new request pipeline plugin API. willSendResponse can be async and will allow you to modify the response. For error reporting, didEncounterErrors (https://github.com/apollographql/apollo-server/pull/2719) is the hook to use.

@martijnwalraven I can't find anything in the docs any of this. Has this been released?

Do you have an example of where/how the didEncounterErrors hook is used?

@bertero Sorry for the late response I havn't implemented any solution for this but you could use graphql-middleware](https://github.com/prisma/graphql-middleware) to do I I'd say

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deathg0d picture deathg0d  路  3Comments

dupski picture dupski  路  3Comments

jpcbarros picture jpcbarros  路  3Comments

dbrrt picture dbrrt  路  3Comments

espoal picture espoal  路  3Comments