-
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
Apollo server 2.0. - RESTDataSource access to full response obj (headers,...) #1324
Labels
⛲️ feature
New addition or enhancement to existing solutions
Comments
4 tasks
PR merged |
Are there docs on how to use this functionality? I am not able to get it to work as the explanation above leads me to believe |
trevor-scheer
added a commit
to apollographql/datasource-rest
that referenced
this issue
Dec 3, 2022
The naming of this hook is deceiving; if this hook is overridden it becomes responsible for returning the parsed body. It was originally introduced in apollographql/apollo-server#1324, where the author claims they implemented it due to lack of access to the complete response (headers) in the fetch methods (get, post, ...). This approach isn't a type safe way to acoomplish this. This hook is now just an observability hook which receives a clone of the response and the request that was sent. A change following this will introduce the ability to fetch a complete response (headers included) aside from the provided fetch methods which only return a body, which will reinstate the functionality that the author of this hook had originally intended.
trevor-scheer
added a commit
to apollographql/datasource-rest
that referenced
this issue
Dec 5, 2022
The naming of this hook is deceiving; if this hook is overridden it becomes responsible for returning the parsed body and handling errors if they occur. It was originally introduced in apollographql/apollo-server#1324, where the author implemented it due to lack of access to the complete response (headers) in the fetch methods (get, post, ...). This approach isn't a type safe way to accomplish this and places the burden of body parsing and error handling on the user. Removing this hook is a prerequisite to a subsequent change that will introduce the ability to fetch a complete response (headers included) aside from the provided fetch methods which only return a body. This change will reinstate the functionality that the author of this hook had originally intended in a more direct manner. We can consider reinstating this hook or something similar in the future with well-documented and use-case-driven semantics. Without knowing other reasons for why this hook should exist (aside from mentioned issue, which will be addressed with an alternative approach), trying to guess what this hook should do or mean is a bit pointless.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In my datasource, I currently need access to the headers of the response.
To do that I added a protected method
didReceiveResponse
likedidReceiveErrorResponse
in theRESTDataSource
class. I can then overwrite this method in an implementation of aRESTDataSource
class where I need access to the headers (e.g to return the link in the headers).Example
I have created a PR to add this method to
RESTDataSource.ts
(PR #1325)The text was updated successfully, but these errors were encountered: