The controlled Z (CZ) operations acting separately on pairs of qubits are commonly adopted in the schemes of generating graph states, the multi-partite entangled states for the one-way quantum computing. For this purpose, we propose a setup of cascade CZ operation on a whole group of qubits in sequence. The operation of the setup starts with entangling an ancilla photon to the first photon as qubit, and this ancilla automatically moves from one entanglement link to another in assisting the formation of a string in graph states. The generation of some special types of graph states, such as the three-dimensional ones, can be greatly simplified in this approach. The setup presented uses weak nonlinearities, but an implementation using probabilistic linear optics is also possible.