Is the association a self-reference of student? Or does it have another class at the end of the association?
If there is another class "Study" (as an example) and the associations would be between them with the cardinality *, then a solution could be:
context Student s:
inv only_one_graduate_type:
( (s.graduate -> notEmpty() implies s.undergraduate -> isEmpty()) &&
(s.undergraduate -> notEmpty() implies s.graduate -> isEmpty()) )
If you use something like Student.allInstances-> better rewrite your OCL expression using a context Student s