Bergman's lemma for graded rings