Failed to import Grasshopper modules in Rhino 8 script editor

The following import statement was fine when run in GHPython in Rhino 7:

from Grasshopper.Kernel.GH_DataMapping import Flatten, Graft

The same statement when run in the Script Editor in Rhino 8 gives me the error ModuleNotFoundError: No module named ‘Grasshopper.Kernel.GH_DataMapping’. Importing Grasshopper.Kernel is fine, but I can’t import any of its submodules. I can run Grasshopper.Kernel.GH_DataMapping.Flatten normally as well.

How should I write this import instead?