Graininess can occur if the cheese is overheated, causing the proteins to clump together. To prevent this, remove your sauce from the heat before adding the cheese, and let it melt slowly.