Use the point of a sharp knife to cut small slits in the eggplants. Wiggle the knife sideways to open each slit just wide enough to insert a sliver of garlic. Wrap the eggplants in foil and place in the roasting pan. Roast until soft, about 90 minutes. Remove them from the oven and allow to cool. Keep the oven on.
Remove the foil and cut the eggplants in half from stem to bottom. Place in a colander over the roasting pan and drain any of the bitter liquid.
Scoop out the pulp and the garlic slivers and put them into the bowl of the food processor. Cube 1 tablespoon of the butter and add it to the bowl. Process until smooth. Transfer the mixture into the large bowl and stir in the Gruyere, beaten egg, and the sour cream. Set aside.
In the large skillet, melt the remaining 1 tablespoon of butter (or olive oil) over medium heat. Add the sliced mushrooms and cook until they soften and brown, about 5 minutes. Fold into the eggplant mixture and add salt and pepper to taste.
Spread the mixture into the baking pan or pie pan and smooth the top with the back of a spoon or a spatula. Bake in the preheated oven for about 30 minutes. Serve immediately with a little extra Gruyere grated on top of each serving.