Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] async formatResponse and formatError #2274

Closed
vinicius73 opened this issue Feb 5, 2019 · 9 comments
Closed

[feature] async formatResponse and formatError #2274

vinicius73 opened this issue Feb 5, 2019 · 9 comments

Comments

@vinicius73
Copy link

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

@dunika
Copy link

dunika commented Mar 21, 2019

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.

@tanduong
Copy link

tanduong commented Apr 2, 2019

Same!

@BrenoMazieiro
Copy link

Same

@KyleAWang
Copy link

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

@Renaud009
Copy link

Renaud009 commented May 6, 2019

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.

@bertero
Copy link

bertero commented Jun 12, 2019

@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?

@martijnwalraven
Copy link
Contributor

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 (#2719) is the hook to use.

@dunika
Copy link

dunika commented Jul 11, 2019

@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

@taikn
Copy link

taikn commented Jul 11, 2019

@dunika Docs seem to be still WIP, I found a preview here:
https://github.com/apollographql/apollo-server/blob/abernix/docs-plugins/docs/source/features/plugins.md
and here is the example of using the hook:
#1709 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants