How to query APB1 clock frequency?
You can't query, because in the general case the system itself has no idea what the frequency is, only ratios between internal clocks and the external source clock (crystal or solid-state oscillator), and a whole range of frequencies are permissible for the source clock.  The ratios can be read from PLL and/or clock divider configs.

A few microcontrollers will allow only a single value for the external crystal when certain communication circuits are in use, such as Ethernet, high speed USB, or wireless radios.  But even those will allow clocks to vary to achieve power savings.

On most microcontroller models it is possible to determine the clocks without knowing which crystal is in use, by measuring the ratio of two timers, one driven by main system clock, and another driven by slow reference clock (nearly all have a 32 kHz, either as an internal oscillator circuit or a secondary crystal).  But that requires assigning a timer resource to the task and waiting a bit, so it's not something you just want to throw into a uart setup function.

Generally, you just make the same choice STM32 did for the HAL function/macro you are using -- require the system developer to pass in the clock rate he's chosen.  Actually measuring the frequency would generally only be done in circumstances where you expect drift, such as extreme temperatures, or high frequency digital signals that might be coupling onto your clock pins.