The simplest explanation will be:
In structure from motion, it estimates structure(xyz points), camera locations, camera intrinsic.
In graph optimization, it only estimates camera locations. In the graph SLAM, the structure is just a by-product of a corrected trajectory or graph nodes.
E.g. implementing Bundle adjustment with g2o -> You can do it by modifying g2o but simply there is no reason to do that. g2o is not designed to estimate the structure and camera intrinsic. It doesn't mean that you can't estimate these but BA and SLAM are fundamentally different. You will end up changing 99% of the existing g2o code.
implementing factor graph optimization with ceres solver ? -> Ceres solver is an optimization library, not a bundle adjustment software although one of the ceres problem examples is bundle adjustmemt. Anyway, you can modify ceres bundle adjustment example to do graph optimization with a lot of modifications.