My question is how to reuse existing connections in Apollo-server or how to implement connection pooling so I solve the issue described below:
Don’t know if this works but you could try the following.
var http = require('http'); http.globalAgent.keepAlive = true; var https = require('https'); https.globalAgent.keepAlive = true;
Since the REST data source seems to get the fetch function from these two libraries.
Keep in mind this would apply it globally so if any other libraries use this it would have the keep alive option enabled also.
I have never tested this, so let me know if it works as I am interested in it also.
I think another way would be the pass keepalive option as a third parameter in your API call.
For all methods, the third parameter is an
initobject that enables you to provide additional options (such as headers and referrers) to the
fetchAPI that’s used to send the request. For details, see MDN’s fetch docs.
And if you follow that you will see a keepalive option.
I haven’t tried any of these, hope one of them works.