Abstract Doped semiconductors are a central and crucial component of all integrated circuits. By using a combination of white light and a focused laser beam, and exploiting hexagonal boron nitride (hBN) defect states, heterostructures of hBN/Graphene/hBN are photodoped in-operando, reproducibly and reversibly. We demonstrate device geometries with spatially-defined doping type and magnitude. After each optical doping procedure, magnetotransport measurements including quantum Hall measurements are performed to characterize the device performance. In the unipolar (p+–p–p+ and n–n+–n) configurations, we observe quantization of the longitudinal resistance, proving well-defined doped regions and interfaces that are further analyzed by Landauer–Buttiker modeling. Our unique measurements and modeling of these optically doped devices reveal a complete separation of the p- and n-Landau level edge states. The non-interaction of the edge states results in an observed ‘insulating’ state in devices with a bi-polar p–n–p configuration that is uncommon and has not been measured previously in graphene devices. This insulating state could be utilized in high-performance graphene electrical switches. These quantitative magnetotransport measurements confirm that these doping techniques can be applied to any two-dimensional materials encapsulated within hBN layers, enabling versatile, rewritable circuit elements for future computing and memory applications.