There certainly is gravity in space! If there wasn’t, the moon wouldn’t revolve around the earth, and the planets wouldn’t revolve around the sun.
The strength of the force of gravity between any two objects depends on two factors: the mass of the two objects and the distance between them. The heavier the objects are, the stronger the gravitational force between them. The greater the distance between them, the weaker this gravitational force.
If two objects are very massive, as in the case of the sun and the earth, then the gravitational force between them will be strong, even when they’re far apart. That’s why the earth is held in its orbit by the gravitational pull of the sun, even though the sun is 93 million miles away.
The mass of a spaceship is very small compared to the mass of the earth or the sun. As a spaceship moves away from earth, the gravitational pull of the earth decreases until it is too weak to have an effect on the spaceship. But at every point in the universe, there is some gravitational force working on every object.