apollo-tooling: schema publish error: read ECONNRESET

hi there, i am using the new apollo-cli to upload schema but aways get ECCONNRESET error:

image

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Workaround

Step 1 npm i -g proxy-agent

Step 2 append code below to /usr/local/lib/node_modules/apollo/node_modules/apollo-env/lib/fetch/fetch.js (this path is from my Mac, change global node_modules according to your system)

var ProxyAgent = require("proxy-agent");
var proxy = "socks://127.0.0.1:1080";  // or "http://127.0.0.1:8001"
var agent = new ProxyAgent(proxy);
exports.fetch = function(url, options) {
  return require("node-fetch").default(url, { ...options, agent });
};

Why command apollo depends on apollo-env which use node-fetch node-fectch can accept a agent option for proxy : https://www.npmjs.com/package/node-fetch#options proxy-agent provides such agent (http,https,socks5,etc…) : https://github.com/TooTallNate/node-proxy-agent

For apollo-vscode ~/.vscode/extensions/apollographql.vscode-apollo-1.4.0/node_modules/apollo-env/lib/fetch/fetch.js

var ProxyAgent = require("/usr/local/lib/node_modules/proxy-agent"); //use global proxy-agent
...

@sirkay777 ,Thanks,I update it as follow

set terminal proxy for mac

alias proxy='export all_proxy=socks5://127.0.0.1:1080'
alias unproxy='unset all_proxy'

when want to proxy:

proxy

when want unuse proxy

unproxy

I don’t know why this does not work. For me ,below is work!

Step 2

append code below to /usr/local/lib/node_modules/apollo/node_modules/apollo-env/lib/fetch/fetch.js (this path is from my Mac, change global node_modules according to your system)

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ProxyAgent = require("proxy-agent");
var proxy = "socks://127.0.0.1:1080";  // or "http://127.0.0.1:8001"
var agent = new ProxyAgent(proxy);
var node_fetch_1 = require("node-fetch");
//exports.fetch = node_fetch_1.default;
exports.fetch = function(url, options) {
	if(url.indexOf('localhost')>-1){
		return node_fetch_1.default(url,options);
	}
  return node_fetch_1.default(url, { ...options, agent });
};
exports.Request = node_fetch_1.Request;
exports.Response = node_fetch_1.Response;
exports.Headers = node_fetch_1.Headers;
//# sourceMappingURL=fetch.js.map

For apollo-vscode

~/.vscode/extensions/apollographql.vscode-apollo-1.4.0/node_modules/apollo-env/lib/fetch/fetch.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

var ProxyAgent = require("/usr/local/lib/node_modules/proxy-agent"); //use global proxy-agent
var proxy = "socks://127.0.0.1:1080";  // or "http://127.0.0.1:8001"
var agent = new ProxyAgent(proxy);

var node_fetch_1 = require("node-fetch");
//exports.fetch = node_fetch_1.default;
exports.fetch = function(url, options) {
	if(url.indexOf('localhost')>-1){
		return node_fetch_1.default(url,options);
	}
  return node_fetch_1.default(url, { ...options, agent });
};
exports.Request = node_fetch_1.Request;
exports.Response = node_fetch_1.Response;
exports.Headers = node_fetch_1.Headers;
//# sourceMappingURL=fetch.js.map

This issue should not be closed, we need something like --proxy flag or https_proxy env.