Finely grate the cheese. Peel the onions and cut into fine rings.
Put the flour in a bowl. Whisk the eggs and add to the flour. Add salt and water. Mix the flour, eggs, salt and water together.
Place a large saucepan with salted water. Pour the dough into the hot water in portions. Either with a spaetzle slicer, if available, or by spreading the dough thinly on a wooden board and scraping it into the water in thin strips with a knife.
The spaetzle are ready when they swim on the surface of the water. Lift out with a slotted spoon and drain well.
Preheat the oven to 200 ° C. Grease a baking dish.
Layer alternately a layer of spaetzle and a layer of grated cheese in the mold, finish with cheese. Put in the oven and bake for about 10-12 minutes.
In the meantime, melt the butter in a pan and fry the onion rings until golden brown. Serve the onions with the cheese spaetzle.