You could take a look at how godot does it itself on the tilemap editor plugin.
(Here's the header file if needed.)
At a glance I'm not sure whether that algorithm runs every frame, or if it's run once, like you'd expect from drawing commands. (The fact that the plugin is written in C++ means it can afford to redraw everything if needed.)
My assumption would be that you could draw a grid of some size bigger than the screen, and move it with the camera but by increments of
cell_size*10 (arbitrary number) so you can't notice that the grid is moving with the camera. I think the tough part about this is to make sure the grid size is never smaller than the screen if you zoom out too much. Maybe you could redraw the grid to change its size every N zoom steps or something.
Or... perhaps it could be made into a paralax background layer which automatically takes care of tiling it when the camera reaches the boundaries. You don't even need a huge grid for that, and you just need to update it whenever the cell_size gets changed.
Personally I think I would try the second option. Sounds like it could work and also sounds simple enough. The thing to look out for is to make sure the tiling properly aligns the grids and doesn't overlap lines such that they create some sort of visual artifacts.
I have no clue if that works in the editor, though.