Since Moodle won't know how you define "graduated" as that is determined outside of it, you would need some method to add that into Moodle.
The solution that comes to mind for me immediately would be to create a custom profile field for all users for this purpose and fill it in for those who have graduated. You can do this manually or use the bulk user upload tool to fill out data for custom profile fields as well.
Of course, under GDPR a valid option is not to erase but to anonymize no longer needed personal data and retain it as such, for instance for historical or analytical purposes were anonymized data would be useful. Depending on what you are doing with the data, that may be a better option than removal.
Of course, there is no specific tool for that yet in Moodle, but hopefully based on how the erasure tool will work, it may be available one day.