I tried to using below code, but it is failing to reach api with exception.
class CountriesAPI extends RESTDataSource {
constructor() {
super();
this.baseURL = "http://localhost:9321";
}
// this is the area i want to add custom headers before graphql calls rest-api
willSendRequest(request) {
request.headers.set(
"name", `Tat`
);
console.log(request);
}
async getAllCountries() {
// return this.get("/getData");
try {
return this.get(`/getData`);
} catch (error) {
console.error(error);
}
}
}
I have tried to get response from rest-api using custom headers concept but with the above code, apollo-server is failed to trigger request to rest-api with custom headers.