microsoft / kiota-typescript

TypeScript libraries for Kiota-generated API clients.
https://aka.ms/kiota/docs
MIT License
34 stars 25 forks source link

Specifying http proxy changed in Node@18 and 20 #1103

Open waldekmastykarz opened 6 months ago

waldekmastykarz commented 6 months ago

Since v18, Node ships with a native fetch client. This client requires a different way to specify an HTTP proxy than what we've been supporting in our SDKs so far.

To specify an HTTP proxy for Node's fetch, you need to use the following code (tested on Node v18.19 and v20.11):

import { ProxyAgent } from 'undici';
import { Client } from '@microsoft/microsoft-graph-client';

const dispatcher = new ProxyAgent(process.env.https_proxy);
const fetchOptions = {
  dispatcher
};

Client.initWithMiddleware({
  middleware,
  fetchOptions
});

What's noteworthy:

We should update our FetchOptions interface to support specifying dispatcher.

baywet commented 6 months ago

Thanks for reaching out.

@sebastienlevert and I were chatting about that earlier and he mentioned he made it work. I'll let him provide the specifics when he has time (as you know I'm traveling right now and don't have time to dig into this)

sebastienlevert commented 5 months ago

Just to confirm... This is for Graph JS v3, right? We donc have the middleware initialization anymore IIRC.

As we won't be adding new features over there, I highly doubt we'll get to this.

waldekmastykarz commented 5 months ago

This change affects any code that relies on Node's fetch. I noticed it in Graph JS SDK v3 but if the new TypeScript SDK also uses Node.js fetch, then it would also have the same issue.