-
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-datasource-rest]: Cannot override Content-Type header #2035
Comments
Any resolution/work-around for this? |
Afraid not. Luckily on my end we've got some control over the API we consume so we managed to get |
Too bad. I also have control over the API, but I would have preferred changing the |
I'm experiencing this too... I think we should verify if |
Experiencing this issue too...any suggestions on a workaround? Besides controlling at the server API as @aliasmrchips explained. Edit: I have used npm module |
Another work around is to just straight use const fetch = require('node-fetch')
...
class ExampleAPI extends RESTDataSource {
...
async createSomething(someArgs) {
const data = {...}
const res = await fetch(`${this.baseURL}/example`, {
method: 'POST',
headers: {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json',
},
body: JSON.stringify(data)
}).then(response => response.json())
return this.exampleReducer(res.data)
}
...
} |
Fixed via #2520, in 2.6.0. |
Hi guys,
I am trying to consume an API that follows the JSON:API specification, requiring the
Content-Type
header to be set toapplication/vnd.api+json
.I tried using
willSendRequest
in the resolver:While the
Accept
header is correctly set, theContent-Type
one's value remainsapplication/json
.This is because of the
fetch
method ofRESTDataSource.js
, which overwrites theContent-Type
header afterwillSendRequest
is called (line 140):I think this header should only be overwritten when it is not already set.
Thanks,
Yannick
The text was updated successfully, but these errors were encountered: