I am trying to call Microsoft Graph from a component, different than the main one. As a first step I am declaring a variable for the MSGraphClient's serviceKey like this:
const graphClient: MSGraphClient = this.props.context.serviceScope.consume(MSGraphClient.serviceKey);
If I declare this variable within the main component, i.e. the one, initially rendered by the DefaultWebPart.ts
file, then I'm able to make calls to the Microsoft Graph;
However, it's enough that I declare that variable on a component, different than the main one (I'm still importing the context like that: import { WebPartContext } from "@microsoft/sp-webpart-base")
, but start getting the error message
'TypeError: Cannot read property 'serviceScope' of undefined'
as soon as the variable has been declared.