We introduce a flow of a spatial graph and see how invariants for spatial graphs and handlebody-links are derived from those for flowed spatial graphs. We define a new quandle (co)homology by introducing a subcomplex of the rack chain complex. Then we define quandle colorings and quandle cocycle invariants for spatial graphs and handlebody-links.