This example shows how to give a Managed Identity Graph API write access to a single Sharepoint site using the Graph API or SharePoint API permission "Sites.Selected".
Give the Managed Identity the 'Sites.Selected' permission using this code. Be aware that 'Sites.Selected' is available for both the Graph API and the SharePoint API. Choose your weapon.
Use the PnP.PowerShell module to assign write permissions for the Managed Identity. Using this code.