Sumiran’s answer is very accurate.
Graphite, a mineral made entirely from carbon, is the same as diamonds. Graphite is different from diamond in that it has different molecular structures. Each carbon atom in graphite has four valance electrons. Three of these electrons are used to covalently bond to the next carbon atom. And so on throughout the graphite structure. This gives graphite an abundance of electrons that can conduct electricity.
It is not the same graphite you will find in a pencil. The pencil graphite is made from graphite mixed with clay binder. This makes it a great resistor. Pencil graphite is a good choice if you need to make an electronic circuit that does not require a fixed or variable resistor. You can measure a resistance down to a meter using pencil graphite.