In SPFx web part you will require to request permissions as below.
"webApiPermissionRequests": [
{
"resource": "Microsoft Graph",
"scope": "Sites.ReadWrite.All"
}
]
Once admin approve it you can call API using MSGraphClient.
Call graph api using MSGraphClient refer the below code.
export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
public render(): void {
// ...
this.context.msGraphClientFactory
.getClient()
.then((client: MSGraphClient): void => {
// use MSGraphClient here
});
}
// ...
}