Einstein proposed in his General Relativity theory that what is called gravity is really the result of curved spacetime. The Earth does not orbit the Sun because the Sun is pulling on it. The Earth is simply following the shortest path in four-dimensional spacetime. If you have ever taken a long flight, you probably already know that the shortest distance between two cities is not a straight line. Non-stop flights from the United States to Europe fly over parts of Greenland.
Light travels along a geodesic path between two points in spacetime.
Far from any gravity source, the shortest distance is a straight line in three-dimensional space. Near a massive object, the shortest distance is curved in three-dimensional space. Stephen Hawking gives the nice analogy that what we see is like the curved motion of a shadow on the ground from a plane flying in a straight line over hilly terrain. Einstein's theory of General Relativity is a continuation or extension of Newton's law of gravity. In weak gravity conditions, they will give essentially the same results or predictions.