I want to fetch data from Graph from the new beta versions, specifically the user profiles. When specifying the following code
let provider = new SharePointProvider(this.context);
provider.graph = BetaGraph.fromGraph(provider.graph);
Providers.globalProvider = provider;
I get the following error in the WebPart:
TypeError: Cannot read property 'client' of undefined at Function.fromGraph
Any advise? Do I need to specify the graph context object to connect to the beta endpoint somehow?
@Frank-Ove Kristiansen,
You can set the version on a specific request by using the version
Providers.globalProvider.graph.client.api('/users').version('beta').get().then(v => {
console.log(v);
});
And in mgt-get
, it has a Version parameter:
<mgt-get resource="/me" version="beta"
////////////////////////////// Update:
I found the reason. . BetaGraph.fromGraph
will access Graph.client
and use it to initialize a new betagraph instance. However onInit()
is an asynchronous method, at that time, client
or graph
is not available, thus it will prompt "undefined" error.
We can put provider.graph = BetaGraph.fromGraph(provider.graph);
in another method. for example, i put it in the constructor of my react componment:
Then it works fine, all requests are using beta endpoints
BR