1

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
CeeMoney
  • 215
  • 3
  • 10
  • hmm, interesting ask... check a related feature request filed @ [MGT repo](https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/653). – Dev May 31 '21 at 02:40
  • I saw that before while searching around. Was hoping the only option wasn't overriding the graph client. As much as I want to love the GET component, 90% of the time I can't use it because of the filtering/query limitations of the graph. – CeeMoney May 31 '21 at 03:40
  • yeah, i agree. Unfortunately that's the workaround i see at this point. – Dev May 31 '21 at 04:00

1 Answers1

1

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.