0

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?

1 Answers1

1

@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:

enter image description here

Then it works fine, all requests are using beta endpoints

BR

Baker_Kong
  • 1,739
  • 1
  • 4
  • 9
  • I need to fetch the beta version when using the `` component. This has no version property. Will the first example apply to my whole WebPart, on all my components? – Frank-Ove Kristiansen Jan 15 '21 at 08:47