Transformers Can Learn Connectivity in Some Graphs but Not Others