Structural rigidity and flexibility using graphs of groups