Finely grate the cheese and peel the onions. Cut the onions into fine rings.
Put the flour in a bowl and whisk the eggs. Add the eggs to the flour along with salt and water. Mix until a smooth batter forms.
Fill a large saucepan with salted water and bring to a boil over high heat. Working in portions, add the batter to the boiling water using a spaetzle slicer (if available) or by spreading the batter thinly on a wooden board and scraping it into the water in thin strips with a knife.
The spaetzle are ready when they float to the surface. Use a slotted spoon to lift them out and drain well.
Preheat the oven to 200°C (392°F). Grease a baking dish.
Layer the spaetzle and cheese alternately in the baking dish, starting and ending with a layer of cheese. Bake in the preheated oven for 10-12 minutes until the cheese is melted and lightly golden.
While the spaetzle bakes, melt the butter in a pan over medium heat. Add the onion rings and fry for 5-7 minutes, stirring occasionally, until golden brown. Serve the onions with the cheese spaetzle.