Microsoft Graph Toolkit (MGT) - How do I modify/add request headers for the MGT-GET component?

302 Views Asked by At

Trying to figure out how to modify request headers for the graph client toolkit and have it apply when using the GET component. I don't necessarily want to override the entire graph client.


For reference, here's how you do it:

// Already likely on page, adding as reference
TeamsProvider.microsoftTeamsLib = microsoftTeams;
const provider = new TeamsProvider(config);
    const options = {
        authProvider: provider,
        fetchOptions: { headers: {'ConsistencyLevel':'eventual'}}
    };     
    const client = Client.initWithMiddleware(options);
    provider.graph = new Graph(client)
// Now set provider with new graph
Providers.globalProvider = provider
1

There are 1 best solutions below

0
On

I have gotten this to work without having to re-initialize the graph client by doing this:

Providers.globalProvider.graph.client.config.fetchOptions = { headers: {'ConsistencyLevel':'eventual'}}

You can also remove the request headers by setting fetchOptions to {}. This can be toggled at any time between requests, and can be set even after the globalProvider has been initialized without having to re-create the middleware chain.

I posted a comment in the issues section of the MGT repo here.