Use chained variables in a custom datasource plugin

Hello everyone,
I’m currently developing a custom backend Datasource plugin, and I can’t get chained variables to work.
I’ve checked this part of the doc: Add and manage variables | Grafana documentation
It says that chained variables can be used in data sources if they allow them.
So my question is how can I handle those chained variables in my datasource?

Currently, my datasource is handling two queries:

  • Query A: does not depend on anything, it just retrieves some value from a database and store it in a dashboard variable.
  • Query B: uses the current value of Query A to compute the value of another dashboard variable (no network/database operation)

What’s happening:

  1. Query A starts to execute
  2. Query B starts to execute
  3. Query B is resolved with a falsy value since Query A isn’t resolved yet
  4. Query A is resolved and variable A is initialized

What I want to happen:
Query A gets resolved before Query B starts to execute.

I tried checking the source code of some Grafana’s datasource that are handling those chained variables (InfluxDB datasource for instance), but didn’t figured how it was working.

If you could provide some tips/docs on how to get this working, that could be really helpful !

(I’m working with Grafana 7.5.12)