Diabetes is a common complication that happened in pregnant women, and it often leads to many serious consequences for fetuses and gravidas. Accurate diagnosis of gestational diabetes mellitus (GDM) is the key to providing prompt and precise treatment and disease management. The artificial intelligence-based method is currently the most commonly used auxiliary way for clinical medical diagnosis. However, as all we know, there is no report on the assistance of GDM diagnosis based on artificial intelligence till now. In this work, we collected the clinical samples of 1000 pregnant women from ZhongDa Hospital of Southeast University in Nanjing city, which involves 221 cases of GDM. Then, a matrix factorization method was used to fill up all missing values in the original data. Next, a random forest model was adopted to evaluate the importance of each feature dimension to aid in finding potential clinical markers for the GDM diagnosis. Finally, a novel transformer-based method called TF-GDM was proposed for predicting gestational diabetes mellitus accurately. The results show that our TF-GDM method achieves excellent performance, with the accuracy, precision, and recall of 0.93, 0.88, and 0.92, respectively, and also with the F1 score and AUC value of 0.90 and 0.94, respectively. The results demonstrate that our TF-GDM method is significantly better than classic machine learning-based and deep learning-based methods.