The comma is not required. You may leave it out altogether, or put it inside the quotation marks. Source (search for “quotation”). That’s according to CMoS, and assuming you’re using American-style quotation marks (where punctuation normally goes inside the quotation mark). If you’re using British-style quotation marks, then you’d probably leave the first example as you’ve written it (as this source suggests in its final example), though I think the section of rule 5.13.2 which reads “When the requirements of the quotation marks and the main sentence differ, use the stronger mark” should apply (source)—in which case you could leave the comma off. But I haven’t found an official example that speaks to that. I have also seen examples in which the question mark is omitted, which seems like the worst option. I’d personally advise rewording sentences when possible to avoid this problem; none of the solutions seem elegant enough to be invisible to the reader.