-
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
Is there any way to specify a proxy on RESTDataSource? #2090
Comments
Here are a few resources about using additional options with node-fetch (the library being used to make the HTTP requests).
An example from ^1 above to specify a timeout: import { RequestInit } from 'apollo-server-env'
...
const requestInit: RequestInit = {
timeout: 1000,
compress: true,
}
...
const result = await this.get<Item>('item', params, requestInit) So to expand on that example, here is an excerpt of available options for {
// The following properties are node-fetch extensions
follow: 20, // maximum redirect count. 0 to not follow redirect
timeout: 0, // req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies). Signal is recommended instead.
compress: true, // support gzip/deflate content encoding. false to disable
size: 0, // maximum response body size in bytes. 0 to disable
agent: null // http(s).Agent instance, allows custom proxy, certificate, dns lookup etc.
} An (untested) example adding an agent setting: # https://github.com/TooTallNate/node-https-proxy-agent
npm install https-proxy-agent import HttpsProxyAgent from 'https-proxy-agent'
const requestInit: RequestInit = {
timeout: 1000,
compress: true,
agent: new HttpsProxyAgent('http://127.0.0.1:8580')
} Let me know if this works for you, I'll be needing this soon for a project. |
@hiucimon Were you able to test? |
Hi guys, I tried to @sbrichardson suggestion in my an extension of RestDataSource I'm using in all my datasources and it seems to work const { RESTDataSource } = require('apollo-datasource-rest');
const HttpsProxyAgent = require('https-proxy-agent')
const uuid = require('uuid/v1');
class MyAwesomeBaseApi extends RESTDataSource {
willSendRequest(request) {
request.headers.set('x-request-origin', this.context.requestOrigin);
request.headers.set('va-request-id', this.context.requestId || uuid());
request.agent = new HttpsProxyAgent('http://127.0.0.1:8888/')
}
}
module.exports = MyAwesomeBaseApi |
Fairly new to creating Apollo servers, and trying to learn to create them properly, so working on a class using RESTDataSource to fetch data from several API's, but even internal, all my requests have to use our corporate proxies. I can't seem to see a way to get it to use them. Do I need to fall back to fetch?
The text was updated successfully, but these errors were encountered: