The general consensus is derivation from griego, Greek or foreigner in Spain and Latin America. It came into print during the Mexican-American War in the 1840s. Generally applied to Englishmen and Americans disparagingly, now often applied humorously as well.