-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Context in formatError #631
Comments
Any progress on this or a work around? |
What is your use case for this? As a workaround, you should be able to store the context as a local variable inside the closure. Something like:
|
This forces a re-evaluation of the formatError function on each request - kinda pointless. BTW, how can you get the variables? Part of the |
This doesn't seem possible with apollo-server-koa. When logging and reporting errors, I need to get some info from the request in order to create a relation between the errors and the requester. Has anyone made any progress for this or found workaround that works with the apollo server integrations? |
* Pass the context along to all the extension methods Addresses #1343 With this change you should now be able to implement an extension like so: ```javascript class MyErrorTrackingExtension extends GraphQLExtension { willSendResponse(o) { const { context, graphqlResponse } = o context.trackErrors(graphqlResponse.errors) return o } } ``` Edit by @evans : fixes #1343 fixes #614 as the request object can be taken from context or from requestDidStart fixes #631 "" * Remove context from extra extension functions The context shouldn't be necessary for format, parse, validation, and execute. Format generally outputs the state of the extension. Parse and validate don't depend on the context. Execution includes the context argument as contextValue * Move change entry under vNext
* Pass the context along to all the extension methods Addresses #1343 With this change you should now be able to implement an extension like so: ```javascript class MyErrorTrackingExtension extends GraphQLExtension { willSendResponse(o) { const { context, graphqlResponse } = o context.trackErrors(graphqlResponse.errors) return o } } ``` Edit by @evans : fixes #1343 fixes #614 as the request object can be taken from context or from requestDidStart fixes #631 "" * Remove context from extra extension functions The context shouldn't be necessary for format, parse, validation, and execute. Format generally outputs the state of the extension. Parse and validate don't depend on the context. Execution includes the context argument as contextValue * Move change entry under vNext
Needs this aswell. |
@martijnwalraven An example use case for this is if you have a custom logger object that you attach to the context, you may want to be able to reference that logger in the |
For anyone encountering this issue still, the |
Unfortunately, this doesn't allow you to catch exceptions that are thrown in the early stages of processing request, such as |
@Kl4rity this is discussed with some workaround ideas at #3039 (comment) |
Everyone i got a solution! 🎉 |
Any way to reach the context inside the
formatError
function? I couldn't find anything about it in the docs.The text was updated successfully, but these errors were encountered: