fifemon / graphql-datasource

Grafana datasource plugin to query data from a GraphQL API
https://grafana.com/grafana/plugins/fifemon-graphql-datasource
Other
63 stars 33 forks source link

Support GraphQL query variables #12

Open retzkek opened 4 years ago

retzkek commented 4 years ago

Since GraphQL has first-class variables we should use those rather than directly interpolating in the query string.

Totalus commented 4 years ago

An easy way to implement this is to use two distinct fields in the query configuration, one with the query, another with the variables as a JSON string. The variable string can easily be appended in the POST request to the graphql server. The expressions (e.g. Grafana global variables) could then be replaced in the variable string instead of the query string (or in both if relevant).

retzkek commented 4 years ago

That's a good idea @Totalus, and is how graphiql does it, making it easy for one to copy-paste queries. We'll need to be careful about quoting, can we do any better than raw substitution and leaving quoting up to the user?

The expressions (e.g. Grafana global variables) could then be replaced in the variable string instead of the query string (or in both if relevant).

This is also tricky - do we make a breaking change and only do interpolation in the variable document, or do we risk doing unintended substitutions in the query body (since both Grafana and GraphQL use $var syntax)?

Totalus commented 4 years ago

I didn't mean to "quote" the expressions to replace, sorry for the confusion. As you say it should be raw substitution and quoting of the variables left to the user.

As for the breaking change, if Grafana 7.0 implies some breaking changes in this plugin (not sure about that, you would know more than I do), we could possibly make the change at the same time.

retzkek commented 4 years ago

I didn't mean to "quote" the expressions to replace, sorry for the confusion.

Sorry, I wasn't referring specifically to anything you said, just thinking out loud.

As for the breaking change, if Grafana 7.0 implies some breaking changes in this plugin (not sure about that, you would know more than I do), we could possibly make the change at the same time.

I've started working on upgrading to Grafana v7 libraries. Some components have moved around (as usual...) but I don't think there's anything that will require a user-facing change.

Zeeeski commented 1 year ago

Did this ever get implemented?