We present GFlaT, a new algorithm that uses a graph-neural-network to determine the flavor of neutral B mesons produced in Upsilon(4S) decays. It improves previous algorithms by using the information from all charged final-state particles and the relations between them. We evaluate its performance using B decays to flavor-specific hadronic final states reconstructed in a 362 fb(-1) sample of electron-positron collisions collected at the Upsilon(4S) resonance with the Belle II detector at the SuperKEKB collider. We achieve an effective tagging efficiency of (37.40 +/- 0.43 +/- 0.36%), where the first uncertainty is statistical and the second systematic, which is 18% better than the previous Belle II algorithm. Demonstrating the algorithm, we use B-0 -> J/psi K-S(0) decays to measure the mixing-induced and direct CP violation parameters, S = (0.724 +/- 0.035 +/- 0.009) and C = (-0.035 +/- 0.026 +/- 0.029).