How to add variables for backend data source plugins

I’m developing a backend data source plugins according to the tutorial on https://grafana.com/tutorials/build-a-data-source-backend-plugin/

everything is ok, thanks the tutorial, but I have no idea how to add variables support for backend data source plugins, i found this doc: https://grafana.com/docs/grafana/latest/developers/plugins/add-support-for-variables/ , but I do not konw how to indeed. Maybe add to the QueryEditor.tsx?

thanks.

1 Like

I think the easiest way is to interpolate the variables in the (frontend) data source plugin, and pass them to the backend plugin. Since the backend plugin isn’t running in the browser, you need to pass any dependencies you need.

Thanks. I can do it using

import { getTemplateSrv } from '@grafana/runtime';

the @grafana/runtime canary version including the latest code of grafana, lincluding applyTemplateVariables.

Done. thanks grafana, great tool!

1 Like

I’m glad it worked out for you!