Optical properties in solids, such as refractive index and absorption, hold vast applications ranging from solar panels to sensors, photodetectors, and transparent displays. However, first-principles computation of optical properties from crystal structures is a complex task due to the high convergence criteria and computational cost. Recent progress in machine learning shows promise in predicting material properties, yet predicting optical properties from crystal structures remains challenging due to the lack of efficient atomic embeddings. Here, Graph Neural Network for Optical spectra prediction (GNNOpt) is introduced, an equivariant graph-neural-network architecture featuring universal embedding with automatic optimization. This enables high-quality optical predictions with a dataset of only 944 materials. GNNOpt predicts all optical properties based on the Kramers-Krönig relations, including absorption coefficient, complex dielectric function, complex refractive index, and reflectance. The trained model is applied to screen photovoltaic materials based on spectroscopic limited maximum efficiency and search for quantum materials based on quantum weight. First-principles calculations validate the efficacy of the GNNOpt model, demonstrating excellent agreement in predicting the optical spectra of unseen materials. The discovery of new quantum materials with high predicted quantum weight, such as SiOs, which host exotic quasiparticles with multifold nontrivial topology, demonstrates the potential of GNNOpt in predicting optical properties across a broad range of materials andapplications.