Your questions is lacking a couple of details such as what's the goal of obtaining the bedGraph file, do you want to normalize or scale the read counts, do you want the read counts for the entire genome, what type of data is this, have you tried any tools and found them lacking some options, ....
To answer your general question in a general manner:
bedtools genomecov with
-bg option or
deepTools bamCoverage might be viable options.
bam2bed can be useful:
$ bam2bed < reads.bam | cut -f1-3,5 > reads.bg
This puts the map quality signal into the fourth column of
reads.bg. Other columns are available: http://bedops.readthedocs.io/en/latest/content/reference/file-management/conversion/bam2bed.html
If you're trying to count reads over regions, you could instead do something like:
$ bedmap --echo-ref-name --count --delim '\t' regions.bed <(bam2bed < reads.bam) | sed 's/[:-]/\t/g' > answer.bg