But gravity does affect light. There are two theories for this. General Relativity per Einstein suggests that mass distorts spacetime and light just follows space.
In this case at a black hole space is being sucked into the hole at or faster than the speed of light in a distant frame and therefore light cannot escape because it travels more slowly outward than space is traveling inward (again in the distant rest frame).
In other theories space is at rest and flat. In this case gravity affects light directly. Both theories give the same answers, but imply vastly different realities. That is why physics cannot say exactly what reality is. The same results can be obtained from vastly different assumptions about reality.
Nonetheless, young earth creationists still have the problem of explaining how astronomers can detect light that is 100,000ds, millions and billions of years old when they believe that the universe did not even exist then.
I have never seen a rational explanation except for one: that god created the universe some 6,000 years ago with light already traveling towards the earth and fossils already in the ground in the various aged layers. If so, then god must be wanting to have us think that the universe is quite old in spite of its youth.
But I am not willing to believe that god would trick us in such a fundamental manner. My view is that god wants us to investigate the earth and the universe in a rational scientific manner in order to have a better understanding of his/her creation.
So you have to admit that the universe is much more than 6,000 years old, in spite of what the ancient jews thought. I cannot understand why the christians retained the most stupid early jewish thinking of creation and yet threw away the commandment to celebrate that creation, a commandment stated by god to be celebrated by all people for all time.