How to add Data Explorer Queries automatically from a Plugin?

btw, the answer to this would also be generally useful for a broader set of problems.