Schaefer's theorem for graphs