PQL syntax can be a bit tricky/ugly. It took me some time to figure this out so I thought sharing it isn’t a bad idea.
Get all nodes with a specific class in their last catalog
puppet query 'nodes[certname] {resources {type = "class" and title = "CapitalizedClassname"}}'
This gives us a list of all nodes that have have a class, for example Apache, in their catalog. Maybe want to have a list of all nodes that use a specific module (that could be Apache::Vhosts but not Apache):
puppet query 'nodes[certname] {resources {type = "class" and title ~ "CapitalizedClassname"}}'
The query can be combined with more matchers, for example on the certificate name:
puppet query 'nodes[certname] {certname ~ "^bla-" and resources {type = "class" and title = "CapitalizedClassname"}}'