You're referring to the Euthyphro's dilemma which asks whether goodness is above or below God; did he discover or invent goodness? If it is above him, then we should remove the middle man and he is unnecessary. If it's below him then goodness is arbitrary of whatever he commands.
The Christian answer is that there's a third option as well, that goodness is grounded in God's character, it's internal to God. Goodness = God. It is an essential attribute to God, hence goodness naturally flows from God. He has always been essentially good and perfect.
We may still perceive the position as God's perfection and infallible character to be due to his wilful perfection, rather than some logical necessity; that's not to say that God discovered morality and learned to conform to it. His being is maximally good and the foundation of goodness. Morality Therefore comes out if his own standard rather than external standard to him, 1 Peter 1:16.
Many contemporary philosophers of religion suppose that there are true propositions which exist as platonic abstracta independently of God, including propositions constituting a moral order, to which God must conform in order to be good (wiki).