Now that we are more familiar with Microsoft Graph, it's time to start using it by initiating calls directly to the Graph API from SharePoint Framework. We could build our own HTTP requests for Microsoft Graph, but we also have to get an access token and add to the authorization header, unlike for SharePoint REST API (against which we are already authenticated). But fortunately, the SPFx comes with a built-in GraphHttpClient which is similar to spHttpClient and makes our job a lot easier.
In the simplest scenario, we'll simply call the Graph API to retrieve the Title property of the root SharePoint site at https://{tenant}.sharepoint.com.
- Once again, initiate the scaffolding of a new SharePoint Framework web part project with the following command:
yo @microsoft/sharepoint
- Choose the defaults, and ensure that you select No JavaScript framework for the framework, as this keeps things a bit simpler for us.
- Open the project...