Definitions and some weak etymology appear in most dictionaries with dates of origin varying all over the lot. 'Gook' may have had its beginning as a prostitute in the 19th century and later evolved into an expression (largely military) for any dark or yellow-skinned foreigner ('goo-goo' as in 'baby talk' being any foreign language) by the early 20th century. It began as a derogatory name for people from Haiti, the Philippines, Nicaragua, etc. before WWII and then expanded to mean any Pacific Islander during WWII, the Koreans in the 1950s, and finally the Vietnamese and any Asian by the 1960s
Random Historical Dictionary of American Slang
GOOK I. noun [perhaps dialectal variation of obsolete 'gowk' cuckoo, simpleton] 1. (Originally underworld) a slovenly women, especially a prostitute; ('hence,' disparagingly) a women; BROAD. <1859 'Vocabulary' by Mastell, page 38 Gooh [sic]. A prostitute> < 1890-93 'Slang and Its Analogs III' by Farmer & Henley, page 181, 'gook' (American)' A low prostitute. 2. a foolish or peculiar person