We propose a cavity-QED-based scheme of generating entanglement between atoms. The scheme is scalable to an arbitrary number of atoms, and can be used to generate a variety of multipartite entangled states such as the Greenberger-Horne-Zeilinger, W, and cluster states. Furthermore, with a role switching of atoms with photons, the scheme can be used to generate entanglement between cavity fields. We also introduce a scheme that can generate an arbitrary multipartite field graph state.