Halve the onion and cut into relatively thin slices of even thickness. Cut larger slices in half again. Melt the butter in a wide skillet/frying pan over medium heat and add the onions. Cook the onions, stirring now and then, so that they cook down and gradually start to brown. Reduce heat or add a little more butter if needed if the onions start to burn - you want them to gently brown together so they are caramelized. Towards the end of browning, if you like add a pinch of salt and sugar to add flavor and help them get very slightly crisper. Remove from heat once evenly mid-brown in color and caramelized.
As the onions are cooking, mix together the flour, eggs, and part of the milk until the mixture is smooth. Add the rest of the milk and mix in well then set aside a couple minutes. Bring a wide pot of water to the boil.
Grate the cheese ready for the next step, and preheat the oven to 400F/200C. Butter either a small skillet (mine used here is 8in/20cm) or a medium-small oven dish.
Using a spaetzle maker (or ricer/colander if you don't have one), carefully place spaetzle maker over the pot of boiling water and press the dough through the holes into the water. Once they float to the top, remove with a slotted spoon/strainer to drain then place in a dish and repeat until all of the spaetzle are made.
In the prepared skillet/dish, layer up the speatzle, followed by a layer or cheese, making at least two layers or three depending on your dish, ending with a layer of cheese. Make sure the cheese is spread relatively evenly over the top (add a little extra if needed). Top with a mound of caramelized onions in the middle then place th
Top the cheese-covered spaetzle with a mound of caramelized onions in the middle then place the skillet/dish in the oven and bake for around 10 minutes until the cheese has melted. Serve either as it is, or with a side of green salad, or as a side dish to other mains.